summary refs log tree commit diff
path: root/lib/CatalystX/Dispatcher/AsGraph.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CatalystX/Dispatcher/AsGraph.pm')
-rw-r--r--lib/CatalystX/Dispatcher/AsGraph.pm63
1 files changed, 36 insertions, 27 deletions
diff --git a/lib/CatalystX/Dispatcher/AsGraph.pm b/lib/CatalystX/Dispatcher/AsGraph.pm
index 9f6bfd5..1a1baf2 100644
--- a/lib/CatalystX/Dispatcher/AsGraph.pm
+++ b/lib/CatalystX/Dispatcher/AsGraph.pm
@@ -1,21 +1,39 @@
+package CatalystX::Dispatcher::AsGraph;
+
+# ABSTRACT: Create a graph from Catalyst dispatcher
+
 use MooseX::Declare;
-use Graph::Easy;
-use UNIVERSAL::require;
 
-our $VERSION = '0.02';
+our $VERSION = '0.03';
 
 class CatalystX::Dispatcher::AsGraph {
 
+    use Graph::Easy;
     with 'MooseX::Getopt';
 
-    has [qw/appname output/] => ( is => 'ro', isa => 'Str', required => 1 );
-    has 'graph' => ( is => 'ro', default => sub { Graph::Easy->new } );
+    has [qw/appname output/] => (is => 'ro', isa => 'Str', required => 1);
+
+    has graph => (
+        traits  => ['NoGetopt'],
+        is      => 'ro',
+        default => sub { Graph::Easy->new }
+    );
+    has app => (
+        traits  => ['NoGetopt'],
+        is      => 'rw',
+        isa     => 'Object',
+        lazy    => 1,
+        handles => [qw/dispatcher/],
+        default => sub {
+            my $self = shift;
+            Class::MOP::load_class($self->appname);
+            my $app = $self->appname->new;
+            $app;
+        }
+    );
 
     method run{
-        my $class  = $self->appname;
-        $class->require or die $@;
-        my $app    = $class->new;
-        my $routes = $app->dispatcher->_tree;
+        my $routes = $self->dispatcher->_tree;
         $self->_new_node($routes, '');
     }
 
@@ -36,33 +54,24 @@ class CatalystX::Dispatcher::AsGraph {
     }
 }
 
-
-__END__
-
-=head1 NAME
-
-CatalystX::Dispatcher::AsGraph - Create a graph from Catalyst dispatcher
+1;
 
 =head1 SYNOPSIS
 
     use CatalystX::Dispatcher::AsGraph;
-    my $graph = CatalystX::Dispatcher::AsGraph->new_with_options();
-    $graph->graph;
+
+    my $graph = CatalystX::Dispatcher::AsGraph->new(
+        appname => 'MyApp',
+        output  => 'myactions.png',
+    );
+    $graph->run;
 
 =head1 DESCRIPTION
 
-CatalystX::Dispatcher::AsGraph create a graph for a Catalyst application
-using his dispatcher.
+CatalystX::Dispatcher::AsGraph create a graph for a Catalyst application using his dispatcher.
 
 At the time, only private actions are graphed.
 
-=head1 AUTHOR
-
-Franck Cuny E<lt>franck@lumberjaph.netE<gt>
-
 =head1 SEE ALSO
 
-=head1 LICENSE
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
+L<http://www.catalystframework.org/calendar/2009/14>