Breno G. de Oliveira

NAME

Template::AsGraph - Create a graph from a Template Toolkit file

VERSION

Version 0.01

SYNOPSIS

Given a Template Toolkit filename, it generates a Graph::Easy object with the entire template flow.

  use Template::AsGraph;
  
  # quick graph creation for any TT2 template
  my $graph = Template::AsGraph->graph('mytemplate.tt2');
  
  

You can also set up any TT configurations such as different tag styles and INCLUDE_PATHs. You can even set OUTPUT to actually get the processed template (see documentation below):

  my %config = (
        INCLUDE_PATH => 'root/src/',
        START_TAG    => '<+',
        END_TAG      => '+>',
        PLUGIN_BASE  => 'MyApp::Template::Plugin',
        PRE_PROCESS  => 'header',
        OUTPUT       => \$output,
  );
  my $graph = Template::AsGraph->graph('mytemplate.tt2', \%config);
  
  

Alternatively, if you have dinamically loaded templates, you may want to pass on variables and other TT options just as you would to a regular Template object.

  my $graph = Template::AsGraph->graph('mytemplate.tt2', \%config, \%vars);

The returnerd $graph is a Graph::Easy object, so you can manipulate it at will. For example, save as a PNG file (assuming you have graphviz's "dot" binary)

  if (open my $png, '|-', 'dot -Tpng -o routes.png') {
      print $png $graph->as_graphviz;
      close($png);
  }

DESCRIPTION

graph($template_name)

graph($template_name, \%tt_config)

graph($template_name, \%tt_config, \%tt_vars)

Receives a template name and generates a Graph::Easy object with a representation of the template's flow. It may optionally receive any Template configuration option and variables.

AUTHOR

Breno G. de Oliveira, <garu at cpan.org>

CAVEATS

Although this module should work without any quirks and DWIM for almost everyone, there are some minor issues that can emerge with advanced users:

  • In order to correctly find the processing tree, we wrap TT's Context module on our own. So you won't be able to setup a custom Context object to use with this module. If your version also wraps the original TT Context (and you should), you can easily fix this by inheriting from Template::AsGraph::Context instead of from Template::Context, and just setting it up in the config hash:

       CONTEXT => My::Custom::Context->new(),
  • If, by any chance, you also want to fetch the output of the processed template(s), you'll need to setup the OUTPUT (and, optionally, OUTPUT_PATH). Please refer to Template::Manual::Config for more information on how to get the best out of it.

BUGS

Please report any bugs or feature requests to bug-template-asgraph at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-AsGraph. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Template::AsGraph

You can also look for information at:

ACKNOWLEDGEMENTS

Andy Wardley and his awesome Template Toolkit deserve all the praise. Also, many thanks to Pedro Melo and his MojoX::Routes::AsGraph, which served as inspiration for this module from the main idea down to the actual code.

COPYRIGHT & LICENSE

Copyright 2009 Breno G. de Oliveira, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.