diff options
Diffstat (limited to 'lib/MGA/Mirrors/Controller/Graph.pm')
-rw-r--r-- | lib/MGA/Mirrors/Controller/Graph.pm | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/MGA/Mirrors/Controller/Graph.pm b/lib/MGA/Mirrors/Controller/Graph.pm new file mode 100644 index 0000000..5ca93cf --- /dev/null +++ b/lib/MGA/Mirrors/Controller/Graph.pm @@ -0,0 +1,70 @@ +package MGA::Mirrors::Controller::Graph; +use Moose; +use namespace::autoclean; + +BEGIN {extends 'Catalyst::Controller'; } + +=head1 NAME + +MGA::Mirrors::Controller::Graph - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 index + +=cut + +sub index :Path :Args(0) { + my ( $self, $c ) = @_; + + my $mirror_list = $c->model('Mirrors')->find_mirrors; + my $graph = GraphViz->new(layout => 'dot', overlap => 'orthoxy', rankdir => 1); + my %node; + my %edge; + foreach (@{$mirror_list || []}) { + $node{$_->{hostname}} = $_; + if ($_->{syncfrom}) { + $edge{$_->{syncfrom}}{$_->{hostname}} = 1; + } + } + my %nodadded; + foreach my $from (keys %edge) { + foreach my $to (keys %{ $edge{$from} ||{}}) { + foreach ($from, $to) { + if (!$nodadded{$_}) { + $graph->add_node($_, shape => 'box', cluster => $node{$_}{country}); + } + } + $graph->add_edge($from, $to); + } + } + $c->stash->{graphviz}->{graph} = $graph; +} + +sub end : Private { + my ($self, $c) = @_; + $c->view('GraphViz')->process($c); + $c->model('Mirrors')->db->rollback; +} + +=head1 AUTHOR + +Olivier Thauvin + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; |