[Catalyst-commits] r12262 - trunk/examples/CatalystAdvent/root/2009/pen

garu at dev.catalyst.perl.org garu at dev.catalyst.perl.org
Wed Dec 9 05:46:43 GMT 2009


Author: garu
Date: 2009-12-09 05:46:43 +0000 (Wed, 09 Dec 2009)
New Revision: 12262

Added:
   trunk/examples/CatalystAdvent/root/2009/pen/asgraph.pod
Log:
first take on graphs and graphics for MVc components


Added: trunk/examples/CatalystAdvent/root/2009/pen/asgraph.pod
===================================================================
--- trunk/examples/CatalystAdvent/root/2009/pen/asgraph.pod	                        (rev 0)
+++ trunk/examples/CatalystAdvent/root/2009/pen/asgraph.pod	2009-12-09 05:46:43 UTC (rev 12262)
@@ -0,0 +1,85 @@
+=head1 A Catalyst Carol
+
+Sometimes our Catalyst applications are so large, with such complex business rules, that we can get a little overwhelmed by the myriad of components and structures, or otherwise become just too concentrated in a given subset we might loose perspective of the big picture. Well, fear not!
+
+There are several visualization helper tools available in the Perl world, and in today's Advent Calendar, in the spirit of Dicken's Holiday masterpiece and MVC, we'll look closer into three of them!
+
+=head2 Ghost...erm...Graph of Model Past
+
+  use SQL::Translator;
+
+  my $translator = SQL::Translator->new(
+          from => 'MySQL',
+          to   => 'GraphViz',
+  ) or die SQL::Translator->error;
+  $translator->translate;
+
+If you are using Catalyst with the ever popular DBIx::Class (DBIC) and rather fetch database information from the schema modules, rejoice! All you have to do is choose C<< SQL::Translator::Parser::DBIx::Class >> as the parser, and pass the loaded schema inside the parser_args parameter. Below we describe not only that, but also provide the producer with some customization via C<< producer_args >>:
+
+  use SQL::Translator;
+
+  my $schema = MyApp::Schema->connect;
+  my $translator = SQL::Translator->new(
+      parser        => 'SQL::Translator::Parser::DBIx::Class',
+      parser_args   => { package => $schema },
+      producer      => 'Diagram',
+      producer_args => {
+          out_file       => 'schema.png',
+          output_type    => 'png',
+          title          => 'My Schema',
+      },
+  ) or die SQL::Translator->error;
+
+  $translator->translate;
+
+
+=head2 Graph of Controller Present
+
+  use CatalystX::Dispatcher::AsGraph;
+   
+  my $graph = CatalystX::Dispatcher::AsGraph->new(
+        appname => 'MyApp',
+        output  => 1,
+  );
+  $graph->run;
+  
+B<Note:> As Khisanth pointed out, this module uses MooseX::Declare and has no "package" information, so the CPAN indexer won't index it, and the shell won't find it. Until this is fixed by the author, you'll need to ask for the package's full path (e.g. C<< install FRANCKC/CatalystX-Dispatcher-AsGraph-0.02.tar.gz >> to install it, or just fetch the tarball directly from the web.
+
+=head2 Graph of Template Future
+
+  use Template::AsGraph;
+
+  my $graph = Template::AsGraph->graph('mytemplate.tt2');
+
+However, if you need a way to understand how your templates fit together, it probably means that their chains, structures and flows are so intricated you dynamically load several bits and pieces from all over the place depending on what data is passed to them by the Controller. Don't worry: the C<graph> method can also receive any TT configurations as its second argument, and variables as a third:
+
+  use Template::AsGraph;
+
+  my %config = (
+      INCLUDE_PATH => 'root/src/',
+      START_TAG    => '<+',
+      END_TAG      => '+>',
+      PLUGIN_BASE  => 'MyApp::Template::Plugin',
+      PRE_PROCESS  => 'header',
+  );
+
+  my %vars = (
+       foo => 'bar',
+       bar => 'baz', 
+  );
+  # alternatively, if you have a Catalyst context object lying around,
+  # you can do just like View::TT and try something like:
+  # my %vars = ( %{ $c->stash() }, 
+  #              c    => $c, 
+  #              base => $c->req->base, 
+  #              name => $c->config->{name} 
+  #            );
+
+  my $graph = Template::AsGraph->graph('mytemplate.tt2', \%config, \%vars);
+
+
+=head2 Authors
+
+Breno G. de Oliveira C<< <garu at cpan.org> >>
+
+Bogdan Lucaciu C<< zamolxes at sinapticode.com >>




More information about the Catalyst-commits mailing list