File Coverage

blib/lib/CatalystX/Dispatcher/AsGraph.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package CatalystX::Dispatcher::AsGraph;
2              
3             # ABSTRACT: Create a graph from Catalyst dispatcher
4              
5 2     2   56500 use MooseX::Declare;
  0            
  0            
6              
7             our $VERSION = '0.03';
8              
9             class CatalystX::Dispatcher::AsGraph {
10              
11             use Graph::Easy;
12             with 'MooseX::Getopt';
13              
14             has [qw/appname output/] => (is => 'ro', isa => 'Str', required => 1);
15              
16             has graph => (
17             traits => ['NoGetopt'],
18             is => 'ro',
19             default => sub { Graph::Easy->new }
20             );
21             has app => (
22             traits => ['NoGetopt'],
23             is => 'rw',
24             isa => 'Object',
25             lazy => 1,
26             handles => [qw/dispatcher/],
27             default => sub {
28             my $self = shift;
29             Class::MOP::load_class($self->appname);
30             my $app = $self->appname->new;
31             $app;
32             }
33             );
34              
35             method run{
36             my $routes = $self->dispatcher->_tree;
37             $self->_new_node($routes, '');
38             }
39              
40             method _new_node($parent, $prefix) {
41             my $name = $prefix . $parent->getNodeValue || '';
42             my $node = $self->graph->add_node($name);
43              
44             my $actions = $parent->getNodeValue->actions;
45             for my $action ( keys %{$actions} ) {
46             next if ( ( $action =~ /^_.*/ ) );
47             $self->graph->add_edge( $node, "[action] " . $action);
48             }
49             for my $child ( $parent->getAllChildren ) {
50             my $child_node = $self->_new_node( $child, $name . ' -> ' );
51             $self->graph->add_edge( $node, $child_node );
52             }
53             return $node;
54             }
55             }
56              
57             1;
58              
59              
60             __END__
61             =pod
62              
63             =head1 NAME
64              
65             CatalystX::Dispatcher::AsGraph - Create a graph from Catalyst dispatcher
66              
67             =head1 VERSION
68              
69             version 0.03
70              
71             =head1 SYNOPSIS
72              
73             use CatalystX::Dispatcher::AsGraph;
74              
75             my $graph = CatalystX::Dispatcher::AsGraph->new(
76             appname => 'MyApp',
77             output => 'myactions.png',
78             );
79             $graph->run;
80              
81             =head1 DESCRIPTION
82              
83             CatalystX::Dispatcher::AsGraph create a graph for a Catalyst application using his dispatcher.
84              
85             At the time, only private actions are graphed.
86              
87             =head1 SEE ALSO
88              
89             L<http://www.catalystframework.org/calendar/2009/14>
90              
91             =head1 AUTHOR
92              
93             franck cuny <franck@lumberjaph.net>
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is copyright (c) 2010 by franck cuny.
98              
99             This is free software; you can redistribute it and/or modify it under
100             the same terms as the Perl 5 programming language system itself.
101              
102             =cut
103