Catalyst-View-TT-0.44/000755 000766 000024 00000000000 12604552454 014744 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/Changes000644 000766 000024 00000016452 12604551611 016241 0ustar00etherstaff000000 000000 Revision history for Perl extension Catalyst::View::TT. 0.44 - 2015-10-05 - declare missing prereq on Data::Dump 0.43 - 2015-08-13 - remove mention of deprecated Catalyst::Plugin::Email in documentation 0.42 2014-12-29 - Fixes to test cases to be compatible with Catalyst v5.90080 - Added a Unicode test designed to check new Catalyst function - Docs for above 0.41 2013-02-28 - New local attribute to let you override the default content type when no content type has been set for the response. 0.40 2013-01-15 20:52:14 - Fix hash randomisation breakage in tests (RT#82703) 0.39 2012-04-11 07:40:00 - Fix warning from tests. RT#75104 - Fix ExtUtils::MakeMaker version requirement (due to last release being made with faulty Module::Install). RT#76488 0.38 2012-02-15 20:42:00 - Change documentation to reflect use of Moose. - Change documentation to highlight how to configure UTF-8 in templates. - Change documentation to recommend putting calls to MyApp->path_to into the app class itself, ergo avoiding recursive dependencies and making the view compile standalone. - Change code generated by Catalyst::Helper::View::TT to use Moose. 0.37 2011-07-17 09:20:00 - Allow setting of TT class rather than forcing 'Template' 0.36 2010-10-19 15:00:00 - Fixed subclassing when using expose_methods 0.35 2010-08-26 01:38:00 - Add expose_methods functionality - add template name to exceptions - update render_die message to be more concise. - Doc fixes (RT#57159) - Silence warnings about Template::Provider::Encoding (RT #56310) 0.34 2010-04-07 04:14:50 - Fix the process method to have the previous behaviour of reporting an error to Catalyst if a Template::Exception object is returned by the render method (i.e. when render_die is unset or set to 0). - Fix the warning issued about missing the render_die config option to log using the standard Catalyst logging system (rather than Carping directly), and to only issue the warning at debug level / when in debug mode. The severity of this warning will be increased in a later release. 0.33 2010-03-10 20:08:00 - The "render()" method now throws a warning on exception before returning the exception. To silence the warning, pass 'render_die => 0' to the constructor. Better yet, pass 'render_die => 1' to make it die instead of returning the excption. This will be the default in a future release when unspecified. The Helper will generate new views with render_die => 1. 0.32 2010-02-16 05:55:00 - Various documentation improvements. - Fix repository metadata. 0.31 2009-10-29 19:26:00 - Moved the test actions to their own controller file to silence warning about actions in the app class being deprecated. 0.30 2009-09-12 23:47:00 - Doc fixes: + Expand ::V:: to ::View:: (RT #45792) + Expand ::C:: to ::Controller:: and use $c->view('TT') where appropriate (bricas) + Add note about use CGI in a template making Catalyst hang (Gunnar Strand) - "use warnings" in Catalyst::View::TT and output from the TT helper - Expand TTSite documentation (RT #33838) - Added a test for direct rendering of a template from a view object, without a request. - Added support for running render with a undef context. 0.29 2009-02-20 14:43:00 - Remove extra unwanted .gitignore from manifest 0.28 2009-02-17 20:37:00 - Change from NEXT to MRO::Compat (t0m) - fix pod generated by the helper (RT #33983) - remove stray newline from generated lib/config/col template (RT #35340) 0.27 2008-04-30 12:30:00 - Add copy_config support to PROVIDERS - Document providers and support unary plus for fully qualified class names as in the example in TT pod. 0.26 2008-01-11 20:12:00 - Fix pod coverage - Change from =item to =head2 - Update docs to reflect action change 0.25 2007-01-15 16:06 - The little typo that cold 0.24 2006-11-15 16:34 - Default to .tt extension - pod cleanups for generated file - Move to Module::Install - Use Data::Dump for debug 0.23 Sun Mar 23 20:45:00 2006 - Added render suport. (Ash Berlin) 0.22 Fri Jan 16 18:25:00 2006 - stringify $c->action for automatic template match instead of $c->req->action. * NOTE * This will change the match to the private name of the matched action! if you use template_suffix you have to move your templates around! 0.21 Fri Dec 16 18:25:00 2005 - Added Template::Provider support (Jess Robinson) - Fixed dynamic include bugs and added tests. (Zbigniew Lukasiak) 0.20 Mon Dec 12 03:35:00 2005 - Fall back to action (default/index returns blank on match) - Added tests. (Daniel Westermann-Clark) - Fixed TTSite helper to use correct app name. - Added support for dynamic includes. 0.19 Tue Nov 15 09:52:00 2005 - unbreak config. 0.18 Mon Nov 14 20:43:00 2005 - Fixed more typos 0.17 Mon Nov 14 20:43:00 2005 - Fixed some typos 0.16 Mon Nov 14 20:43:00 2005 - Updated TTSite for Catalyst 5.5 0.15 Mon Nov 14 14:43:00 2005 - Updated for Catalyst 5.5 - Fix docs - Added TEMPLATE_SUFFIX config variable 0.14 Fri Oct 21 10:20:00 2005 - Turn timer off by default, even for debug. - removed superflous 'templates' inside 'root' - made it possible to forward to the message action by passing the message in the stash. (example) - Updated docs to show correct config syntax. 0.13 Fri Oct 07 13:30:00 2005 - Fixed constructor - Big update by Andy Wardley - Much improved docs 0.12 Wed Jul 06 15:24:00 2005 - Fixed, don't set Content-Type on failure - Fixed helper to use [%author%] - Fixed helper templates - Rewrote docs 0.11 Fri Apr 15 16:00:00 2005 - Fixed broken helper. 0.10 Fri Apr 15 16:00:00 2005 - Added POD tests and made them pass. - updated for Catalyst 5 - New TT Helpers. 0.09 Wed Mar 29 13:47:00 2005 - Don't override user-set charset/content-type - Cleaned up the content-type we set. - Updated README to current POD to current POD 0.08 Wed Mar 29 12:22:00 2005 - changed order of stash so stash can override c/base/name - fixed some typos - extended the documentation (Andrew Ford) 0.07 Sat Mar 04 23:00:00 2005 - fixed the bugs produced by draven and the_jester ;) 0.06 Fri Mar 04 20:00:00 2005 - new helper api 0.05 Mon Feb 28 10:00:00 2005 - added helper 0.04 Sun Feb 27 22:00:00 2005 - better debug messages (Marcus Ramberg) 0.03 Thu Feb 17 22:00:00 2005 - don't try to render something without a template 0.02 Tue Feb 01 02:00:00 2005 - using $c->req->match instead of $c->req->action 0.01 Fri Jan 28 22:00:00 2005 - first release Catalyst-View-TT-0.44/MANIFEST000644 000766 000024 00000002634 12604552455 016103 0ustar00etherstaff000000 000000 Changes lib/Catalyst/Helper/View/TT.pm lib/Catalyst/Helper/View/TTSite.pm lib/Catalyst/View/TT.pm maint/Makefile.PL.include Makefile.PL MANIFEST This list of files t/01use.t t/04pkgconfig.t t/05appconfig.t t/06includepath.t t/07render.t t/08cycle.t t/09providers.t t/10providers.encoding.t t/11norequest.t t/12expose_methods.t t/13classconfig.t t/14alt_content_type.t t/lib/TestApp.pm t/lib/TestApp/Controller/Root.pm t/lib/TestApp/FauxProvider.pm t/lib/TestApp/root/any_include_path/test t/lib/TestApp/root/expose_methods.tt t/lib/TestApp/root/specified_template.tt t/lib/TestApp/root/test.tt t/lib/TestApp/root/test_alt_content_type.tt t/lib/TestApp/root/test_include_path/testpath.tt t/lib/TestApp/Template/Any.pm t/lib/TestApp/View/TT/AltContentType.pm t/lib/TestApp/View/TT/Appconfig.pm t/lib/TestApp/View/TT/Classconfig.pm t/lib/TestApp/View/TT/Encoding.pm t/lib/TestApp/View/TT/ExposeMethods.pm t/lib/TestApp/View/TT/ExposeMethodsSubclassed.pm t/lib/TestApp/View/TT/Includepath.pm t/lib/TestApp/View/TT/Includepath2.pm t/lib/TestApp/View/TT/Includepath3.pm t/lib/TestApp/View/TT/Pkgconfig.pm t/lib/TestApp/View/TT/Providerconfig.pm t/root/heart t/utf8.t xt/pod-coverage.t xt/pod-syntax.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) README README file (added by Distar) Catalyst-View-TT-0.44/META.json000644 000766 000024 00000003433 12604552454 016370 0ustar00etherstaff000000 000000 { "abstract" : "Template View Class", "author" : [ "Sebastian Riedel " ], "dynamic_config" : 0, "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Catalyst-View-TT", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Catalyst" : "5.7", "Class::Accessor" : "0", "Data::Dump" : "0", "MRO::Compat" : "0", "Path::Class" : "0", "Template" : "0", "Template::Timer" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "File::Spec" : "0", "Test::More" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Catalyst-View-TT@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-View-TT" }, "repository" : { "type" : "git", "url" : "https://github.com/perl-catalyst/Catalyst-View-TT.git", "web" : "https://github.com/perl-catalyst/Catalyst-View-TT" }, "x_IRC" : "irc://irc.perl.org/#catalyst", "x_MailingList" : "http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" }, "version" : "0.44", "x_serialization_backend" : "JSON::PP version 2.27300" } Catalyst-View-TT-0.44/META.yml000644 000766 000024 00000001740 12604552454 016217 0ustar00etherstaff000000 000000 --- abstract: 'Template View Class' author: - 'Sebastian Riedel ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Catalyst-View-TT no_index: directory: - t - inc requires: Catalyst: '5.7' Class::Accessor: '0' Data::Dump: '0' MRO::Compat: '0' Path::Class: '0' Template: '0' Template::Timer: '0' perl: '5.008001' resources: IRC: irc://irc.perl.org/#catalyst MailingList: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-View-TT repository: https://github.com/perl-catalyst/Catalyst-View-TT.git version: '0.44' x_serialization_backend: 'CPAN::Meta::YAML version 0.017' Catalyst-View-TT-0.44/Makefile.PL000644 000766 000024 00000005126 12604551346 016721 0ustar00etherstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; ExtUtils::MakeMaker->VERSION('7.00') unless -f 'META.yml'; (do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; my %WriteMakefileArgs = ( NAME => 'Catalyst::View::TT', VERSION_FROM => 'lib/Catalyst/View/TT.pm', AUTHOR => 'Sebastian Riedel ', LICENSE => 'perl_5', MIN_PERL_VERSION => 5.008001, # catalyst minimum PREREQ_PM => { 'Catalyst' => '5.7', 'Template' => 0, 'Class::Accessor' => 0, 'Template::Timer' => 0, 'Path::Class' => 0, 'MRO::Compat' => 0, 'Data::Dump' => 0, }, TEST_REQUIRES => { 'Test::More' => '0', 'File::Spec' => '0', }, META_MERGE => { 'meta-spec' => { version => 2 }, dynamic_config => 0, resources => { # r/w: catagits@git.shadowcat.co.uk:Catalyst-View-TT # r/o: git://git.shadowcat.co.uk:catagits/Catalyst-View-TT # web: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits/Catalyst-View-TT.git repository => { url => 'https://github.com/perl-catalyst/Catalyst-View-TT.git', web => 'https://github.com/perl-catalyst/Catalyst-View-TT', type => 'git', }, bugtracker => { mailto => 'bug-Catalyst-View-TT@rt.cpan.org', web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-View-TT', }, x_MailingList => 'http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst', x_IRC => 'irc://irc.perl.org/#catalyst', }, }, ); die 'need to do a merge with CPAN::Meta::Requirements!!' if !-f 'META.yml' && exists $WriteMakefileArgs{BUILD_REQUIRES}; if (!eval { ExtUtils::MakeMaker->VERSION('6.6303') }) { $WriteMakefileArgs{BUILD_REQUIRES} = $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{TEST_REQUIRES}; } if (!eval { ExtUtils::MakeMaker->VERSION('6.5501') }) { @{$WriteMakefileArgs{PREREQ_PM}}{ keys %{$WriteMakefileArgs{BUILD_REQUIRES}} } = @{$WriteMakefileArgs{BUILD_REQUIRES}}{ keys %{$WriteMakefileArgs{BUILD_REQUIRES}} }; delete $WriteMakefileArgs{BUILD_REQUIRES}; } my %mm_req = ( LICENCE => 6.31, META_MERGE => 6.45, META_ADD => 6.45, MIN_PERL_VERSION => 6.48, ); for (keys %mm_req) { unless (eval { ExtUtils::MakeMaker->VERSION($mm_req{$_}) }) { warn "$_ $@" if not -f 'Makefile.PL'; delete $WriteMakefileArgs{$_}; } } WriteMakefile(%WriteMakefileArgs); Catalyst-View-TT-0.44/README000644 000766 000024 00000044434 12604552454 015635 0ustar00etherstaff000000 000000 NAME Catalyst::View::TT - Template View Class SYNOPSIS # use the helper to create your View myapp_create.pl view Web TT # add custom configuration in View/Web.pm __PACKAGE__->config( # any TT configuration items go here TEMPLATE_EXTENSION => '.tt', CATALYST_VAR => 'c', TIMER => 0, ENCODING => 'utf-8' # Not set by default PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', render_die => 1, # Default for new apps, see render method docs expose_methods => [qw/method_in_view_class/], ); # add include path configuration in MyApp.pm __PACKAGE__->config( 'View::Web' => { INCLUDE_PATH => [ __PACKAGE__->path_to( 'root', 'src' ), __PACKAGE__->path_to( 'root', 'lib' ), ], }, ); # render view from lib/MyApp.pm or lib/MyApp::Controller::SomeController.pm sub message : Global { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->stash->{message} = 'Hello World!'; $c->forward( $c->view('Web') ); } # access variables from template The message is: [% message %]. # example when CATALYST_VAR is set to 'Catalyst' Context is [% Catalyst %] The base is [% Catalyst.req.base %] The name is [% Catalyst.config.name %] # example when CATALYST_VAR isn't set Context is [% c %] The base is [% base %] The name is [% name %] DESCRIPTION This is the Catalyst view class for the Template Toolkit. Your application should defined a view class which is a subclass of this module. Throughout this manual it will be assumed that your application is named MyApp and you are creating a TT view named Web; these names are placeholders and should always be replaced with whatever name you've chosen for your application and your view. The easiest way to create a TT view class is through the myapp_create.pl script that is created along with the application: $ script/myapp_create.pl view Web TT This creates a MyApp::View::Web.pm module in the lib directory (again, replacing "MyApp" with the name of your application) which looks something like this: package FooBar::View::Web; use Moose; extends 'Catalyst::View::TT'; __PACKAGE__->config(DEBUG => 'all'); Now you can modify your action handlers in the main application and/or controllers to forward to your view class. You might choose to do this in the end() method, for example, to automatically forward all actions to the TT view class. # In MyApp or MyApp::Controller::SomeController sub end : Private { my( $self, $c ) = @_; $c->forward( $c->view('Web') ); } But if you are using the standard auto-generated end action, you don't even need to do this! # in MyApp::Controller::Root sub end : ActionClass('RenderView') {} # no need to change this line # in MyApp.pm __PACKAGE__->config( ... default_view => 'Web', ); This will Just Work. And it has the advantages that: * If you want to use a different view for a given request, just set << $c->stash->{current_view} >>. (See Catalyst's "$c->view" method for details. * << $c->res->redirect >> is handled by default. If you just forward to "View::Web" in your "end" routine, you could break this by sending additional content. See Catalyst::Action::RenderView for more details. CONFIGURATION There are a three different ways to configure your view class. The first way is to call the "config()" method in the view subclass. This happens when the module is first loaded. package MyApp::View::Web; use Moose; extends 'Catalyst::View::TT'; __PACKAGE__->config({ PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', }); You may also override the configuration provided in the view class by adding a 'View::Web' section to your application config. This should generally be used to inject the include paths into the view to avoid the view trying to load the application to resolve paths. .. inside MyApp.pm .. __PACKAGE__->config( 'View::Web' => { INCLUDE_PATH => [ __PACKAGE__->path_to( 'root', 'templates', 'lib' ), __PACKAGE__->path_to( 'root', 'templates', 'src' ), ], }, ); You can also configure your view from within your config file if you're using Catalyst::Plugin::ConfigLoader. This should be reserved for deployment-specific concerns. For example: # MyApp_local.conf (Config::General format) WRAPPER "custom_wrapper" INCLUDE_PATH __path_to('root/templates/custom_site')__ INCLUDE_PATH __path_to('root/templates')__ might be used as part of a simple way to deploy different instances of the same application with different themes. DYNAMIC INCLUDE_PATH Sometimes it is desirable to modify INCLUDE_PATH for your templates at run time. Additional paths can be added to the start of INCLUDE_PATH via the stash as follows: $c->stash->{additional_template_paths} = [$c->config->{root} . '/test_include_path']; If you need to add paths to the end of INCLUDE_PATH, there is also an include_path() accessor available: push( @{ $c->view('Web')->include_path }, qw/path/ ); Note that if you use include_path() to add extra paths to INCLUDE_PATH, you MUST check for duplicate paths. Without such checking, the above code will add "path" to INCLUDE_PATH at every request, causing a memory leak. A safer approach is to use include_path() to overwrite the array of paths rather than adding to it. This eliminates both the need to perform duplicate checking and the chance of a memory leak: @{ $c->view('Web')->include_path } = qw/path another_path/; If you are calling "render" directly then you can specify dynamic paths by having a "additional_template_paths" key with a value of additional directories to search. See "CAPTURING TEMPLATE OUTPUT" for an example showing this. Unicode (pre Catalyst v5.90080) NOTE Starting with Catalyst v5.90080 unicode and encoding has been baked into core, and the default encoding is UTF-8. The following advice is for older versions of Catalyst. Be sure to set "ENCODING => 'utf-8'" and use Catalyst::Plugin::Unicode::Encoding if you want to use non-ascii characters (encoded as utf-8) in your templates. This is only needed if you actually have UTF8 literals in your templates and the BOM is not properly set. Setting encoding here does not magically encode your template output. If you are using this version of Catalyst you need to all the Unicode plugin, or upgrade (preferred) Unicode (Catalyst v5.90080+) This version of Catalyst will automatically encode your body output to UTF8. This means if your variables contain multibyte characters you don't need top do anything else to get UTF8 output. However if your templates contain UTF8 literals (like, multibyte characters actually in the template text), then you do need to either set the BOM mark on the template file or instruct TT to decode the templates at load time via the ENCODING configuration setting. Most of the time you can just do: MyApp::View::HTML->config( ENCODING => 'UTF-8'); and that will just take care of everything. This configuration setting will force Template to decode all files correctly, so that when you hit the finalize_encoding step we can properly encode the body as UTF8. If you fail to do this you will get double encoding issues in your output (but again, only for the UTF8 literals in your actual template text.) Again, this ENCODING configuration setting only instructs template toolkit how (and if) to decode the contents of your template files when reading them from disk. It has no other effect. RENDERING VIEWS The view plugin renders the template specified in the "template" item in the stash. sub message : Global { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->forward( $c->view('Web') ); } If a stash item isn't defined, then it instead uses the stringification of the action dispatched to (as defined by $c->action) in the above example, this would be "message", but because the default is to append '.tt', it would load "root/message.tt". The items defined in the stash are passed to the Template Toolkit for use as template variables. sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->stash->{message} = 'Hello World!'; $c->forward( $c->view('Web') ); } A number of other template variables are also added: c A reference to the context object, $c base The URL base, from $c->req->base() name The application name, from $c->config->{ name } These can be accessed from the template in the usual way: : The message is: [% message %] The base is [% base %] The name is [% name %] The output generated by the template is stored in "$c->response->body". CAPTURING TEMPLATE OUTPUT If you wish to use the output of a template for some other purpose than displaying in the response, e.g. for sending an email, this is possible using other views, such as Catalyst::View::Email::Template. TEMPLATE PROFILING See "TIMER" property of the config method. METHODS new The constructor for the TT view. Sets up the template provider, and reads the application config. process($c) Renders the template specified in "$c->stash->{template}" or "$c->action" (the private name of the matched action). Calls render to perform actual rendering. Output is stored in "$c->response->body". It is possible to forward to the process method of a TT view from inside Catalyst like this: $c->forward('View::Web'); N.B. This is usually done automatically by Catalyst::Action::RenderView. render($c, $template, \%args) Renders the given template and returns output. Throws a Template::Exception object upon error. The template variables are set to %$args if $args is a hashref, or "$c->stash" otherwise. In either case the variables are augmented with "base" set to "$c->req->base", "c" to $c, and "name" to "$c->config->{name}". Alternately, the "CATALYST_VAR" configuration item can be defined to specify the name of a template variable through which the context reference ($c) can be accessed. In this case, the "c", "base", and "name" variables are omitted. $template can be anything that Template::process understands how to process, including the name of a template file or a reference to a test string. See Template::process for a full list of supported formats. To use the render method outside of your Catalyst app, just pass a undef context. This can be useful for tests, for instance. It is possible to forward to the render method of a TT view from inside Catalyst to render page fragments like this: my $fragment = $c->forward("View::Web", "render", $template_name, $c->stash->{fragment_data}); Backwards compatibility note The render method used to just return the Template::Exception object, rather than just throwing it. This is now deprecated and instead the render method will throw an exception for new applications. This behaviour can be activated (and is activated in the default skeleton configuration) by using "render_die => 1". If you rely on the legacy behaviour then a warning will be issued. To silence this warning, set "render_die => 0", but it is recommended you adjust your code so that it works with "render_die => 1". In a future release, "render_die => 1" will become the default if unspecified. template_vars Returns a list of keys/values to be used as the catalyst variables in the template. config This method allows your view subclass to pass additional settings to the TT configuration hash, or to set the options as below: paths The list of paths TT will look for templates in. expose_methods The list of methods in your View class which should be made available to the templates. For example: expose_methods => [qw/uri_for_css/], ... sub uri_for_css { my ($self, $c, $filename) = @_; # additional complexity like checking file exists here return $c->uri_for('/static/css/' . $filename); } Then in the template: [% uri_for_css('home.css') %] content_type This lets you override the default content type for the response. If you do not set this and if you do not set the content type in your controllers, the default is "text/html; charset=utf-8". Use this if you are creating alternative view responses, such as text or JSON and want a global setting. Any content type set in your controllers before calling this view are respected and have priority. "CATALYST_VAR" Allows you to change the name of the Catalyst context object. If set, it will also remove the base and name aliases, so you will have access them through . For example, if CATALYST_VAR has been set to "Catalyst", a template might contain: The base is [% Catalyst.req.base %] The name is [% Catalyst.config.name %] "TIMER" If you have configured Catalyst for debug output, and turned on the TIMER setting, "Catalyst::View::TT" will enable profiling of template processing (using Template::Timer). This will embed HTML comments in the output from your templates, such as: .... "TEMPLATE_EXTENSION" a suffix to add when looking for templates bases on the "match" method in Catalyst::Request. For example: package MyApp::Controller::Test; sub test : Local { .. } Would by default look for a template in /test/test. If you set TEMPLATE_EXTENSION to '.tt', it will look for /test/test.tt. "PROVIDERS" Allows you to specify the template providers that TT will use. MyApp->config( name => 'MyApp', root => MyApp->path_to('root'), 'View::Web' => { PROVIDERS => [ { name => 'DBI', args => { DBI_DSN => 'dbi:DB2:books', DBI_USER=> 'foo' } }, { name => '_file_', args => {} } ] }, ); The 'name' key should correspond to the class name of the provider you want to use. The _file_ name is a special case that represents the default TT file-based provider. By default the name is will be prefixed with 'Template::Provider::'. You can fully qualify the name by using a unary plus: name => '+MyApp::Provider::Foo' You can also specify the 'copy_config' key as an arrayref, to copy those keys from the general config, into the config for the provider: DEFAULT_ENCODING => 'utf-8', PROVIDERS => [ { name => 'Encoding', copy_config => [qw(DEFAULT_ENCODING INCLUDE_PATH)] } ] This can prove useful when you want to use the additional_template_paths hack in your own provider, or if you need to use Template::Provider::Encoding "CLASS" Allows you to specify a custom class to use as the template class instead of Template. package MyApp::View::Web; use Moose; extends 'Catalyst::View::TT'; use Template::AutoFilter; __PACKAGE__->config({ CLASS => 'Template::AutoFilter', }); This is useful if you want to use your own subclasses of Template, so you can, for example, prevent XSS by automatically filtering all output through "| html". HELPERS The Catalyst::Helper::View::TT and Catalyst::Helper::View::TTSite helper modules are provided to create your view module. There are invoked by the myapp_create.pl script: $ script/myapp_create.pl view Web TT $ script/myapp_create.pl view Web TTSite The Catalyst::Helper::View::TT module creates a basic TT view module. The Catalyst::Helper::View::TTSite module goes a little further. It also creates a default set of templates to get you started. It also configures the view module to locate the templates automatically. NOTES If you are using the CGI module inside your templates, you will experience that the Catalyst server appears to hang while rendering the web page. This is due to the debug mode of CGI (which is waiting for input in the terminal window). Turning off the debug mode using the "-no_debug" option solves the problem, eg.: [% USE CGI('-no_debug') %] SEE ALSO Catalyst, Catalyst::Helper::View::TT, Catalyst::Helper::View::TTSite, Template::Manual AUTHORS Sebastian Riedel, "sri@cpan.org" Marcus Ramberg, "mramberg@cpan.org" Jesse Sheidlower, "jester@panix.com" Andy Wardley, "abw@cpan.org" Luke Saunders, "luke.saunders@gmail.com" COPYRIGHT This program is free software. You can redistribute it and/or modify it under the same terms as Perl itself. Catalyst-View-TT-0.44/lib/000755 000766 000024 00000000000 12604552454 015512 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/maint/000755 000766 000024 00000000000 12604552454 016054 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/000755 000766 000024 00000000000 12604552454 015207 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/xt/000755 000766 000024 00000000000 12604552454 015377 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/xt/pod-coverage.t000644 000766 000024 00000000141 12563006705 020130 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Pod::Coverage 1.04; all_pod_coverage_ok(); Catalyst-View-TT-0.44/xt/pod-syntax.t000644 000766 000024 00000000124 12563006705 017664 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use Test::Pod 1.14; all_pod_files_ok(); Catalyst-View-TT-0.44/t/01use.t000644 000766 000024 00000000176 12562667100 016333 0ustar00etherstaff000000 000000 use strict; use Test::More tests => 2; BEGIN { use_ok('Catalyst::View::TT') } BEGIN { use_ok('Catalyst::Helper::View::TT') } Catalyst-View-TT-0.44/t/04pkgconfig.t000644 000766 000024 00000000771 12562667100 017512 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 5; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $view = 'Pkgconfig'; my $response; ok(($response = request("/test?view=$view"))->is_success, 'request ok'); is($response->content, TestApp->config->{default_message}, 'message ok'); my $message = scalar localtime; ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok'); is($response->content, $message, 'message ok') Catalyst-View-TT-0.44/t/05appconfig.t000644 000766 000024 00000000770 12562667100 017511 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 5; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $view = 'Appconfig'; my $response; ok(($response = request("/test?view=$view"))->is_success, 'request ok'); is($response->content, TestApp->config->{default_message}, 'message ok'); my $message = scalar localtime; ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok'); is($response->content, $message, 'message ok') Catalyst-View-TT-0.44/t/06includepath.t000644 000766 000024 00000002763 12562667100 020050 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 10; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $response; my $inital_include_path = [ @{ TestApp->view('TT::Appconfig')->include_path } ]; ok(($response = request("/test_includepath?view=Appconfig&template=testpath.tt&additionalpath=test_include_path"))->is_success, 'additional_template_path request'); is($response->content, TestApp->config->{default_message}, 'additional_template_path message'); is_deeply($inital_include_path, TestApp->view('TT::Appconfig')->include_path, 'Include path is unchanged'); ok(($response = request("/test_includepath?view=Includepath&template=testpath.tt"))->is_success, 'scalar include path from config request'); is($response->content, TestApp->config->{default_message}, 'scalar include path with delimiter from config message'); ok(($response = request("/test_includepath?view=Includepath2&template=testpath.tt"))->is_success, 'object ref (that stringifys to the path) include path from config request'); is($response->content, TestApp->config->{default_message}, 'object ref (that stringifys to the path) include path from config message'); ok(($response = request("/test_includepath?view=Includepath3&template=testpath.tt&addpath=test_include_path"))->is_success, 'array ref include path from config not replaced by another array request'); is($response->content, TestApp->config->{default_message}, 'array ref include path from config not replaced by another array message'); Catalyst-View-TT-0.44/t/07render.t000644 000766 000024 00000001411 12562667100 017015 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 7; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $response; ok(($response = request("/test_render?template=specified_template.tt¶m=parameterized"))->is_success, 'request ok'); is($response->content, "I should be a parameterized test in @{[TestApp->config->{name}]}", 'message ok'); my $message = 'Dynamic message'; ok(($response = request("/test_msg?msg=$message"))->is_success, 'request ok'); is($response->content, "$message", 'message ok'); $response = request("/test_render?template=non_existant_template.tt"); is (403, $response->code, 'request returned error'); is($response->content, 'file error - non_existant_template.tt: not found', 'Error from non-existant-template'); Catalyst-View-TT-0.44/t/08cycle.t000644 000766 000024 00000001070 12562667100 016637 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use FindBin; use lib "$FindBin::Bin/lib"; plan tests => 3; use_ok('Catalyst::View::TT'); use_ok('Catalyst::Test', 'TestApp'); my $copy; { my $view = new Catalyst::View::TT("TestApp", {}); # Can't Test::Memory::Cycle test since it doesn't detect # [ sub { $copy->paths } ] # as a cycle, but the above does prevent it getting garbage collected. # # memory_cycle_ok($view, 'No cycles in View'); $copy = $view; Scalar::Util::weaken($copy); } ok(!defined $copy, 'Copy went out of scope'); Catalyst-View-TT-0.44/t/09providers.t000644 000766 000024 00000001060 12562667100 017555 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 5; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $response; ok(($response = request("/test_includepath?view=Providerconfig&template=test.tt"))->is_success, 'provider request'); cmp_ok($response->content, 'eq', 'Faux-tastic!', 'provider worked'); ok(($response = request("/test_includepath?view=Providerconfig&template=testpath.tt&additionalpath=test_include_path"))->is_success, 'provider request'); cmp_ok($response->content, 'eq', 'Faux-tastic!', 'provider worked'); Catalyst-View-TT-0.44/t/10providers.encoding.t000644 000766 000024 00000000737 12562667100 021344 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; eval "use Template::Provider::Encoding"; if ($@) { plan skip_all => 'Template::Provider::Encoding'; } else { plan tests => 3; } use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $response; ok(($response = request("/test_includepath?view=Encoding&template=test.tt&additionalpath=test_include_path"))->is_success, 'provider request'); cmp_ok($response->content, 'eq', 'hi', 'provider worked'); Catalyst-View-TT-0.44/t/11norequest.t000644 000766 000024 00000000452 12562667100 017562 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 3; use FindBin; use lib "$FindBin::Bin/lib"; BEGIN { use_ok 'TestApp' or die } ok my $tt = TestApp->view, 'Get TT view object'; is $tt->render(undef, 'test.tt', { message => 'hello' }), 'hello', 'render() should return the template output'; Catalyst-View-TT-0.44/t/12expose_methods.t000644 000766 000024 00000000761 12562667100 020567 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $response; ok(($response = request("/test?view=ExposeMethods&template=expose_methods.tt"))->is_success, 'request ok'); is($response->content, "magic added param", 'message ok'); ok(($response = request("/test?view=ExposeMethodsSubclassed&template=expose_methods.tt"))->is_success, 'request ok'); is($response->content, "magic added param", 'message ok'); done_testing; Catalyst-View-TT-0.44/t/13classconfig.t000644 000766 000024 00000000773 12562667100 020040 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More tests => 5; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); my $view = 'Classconfig'; my $response; ok(($response = request("/test?view=$view"))->is_success, 'request ok'); is($response->content, TestApp->config->{default_message}, 'message ok'); my $message = scalar localtime; ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok'); is($response->content, $message, 'message ok') Catalyst-View-TT-0.44/t/14alt_content_type.t000644 000766 000024 00000001025 12563006275 021111 0ustar00etherstaff000000 000000 use strict; use warnings; use Test::More; use FindBin; use lib "$FindBin::Bin/lib"; use_ok('Catalyst::Test', 'TestApp'); # Hack to support Catalyst v5.90080+ (JNAP) if(TestApp->can('encoding') and (my $enc = TestApp->encoding) and TestApp->can('clear_encoding')) { is(request("/test_alt_content_type")->header('Content-Type'), "text/plain; charset=${\$enc->mime_name}", "Plain text with ${\$enc->mime_name}"); } else { is(request("/test_alt_content_type")->header('Content-Type'), 'text/plain', 'Plain Text'); } done_testing; Catalyst-View-TT-0.44/t/lib/000755 000766 000024 00000000000 12604552454 015755 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/root/000755 000766 000024 00000000000 12604552454 016172 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/utf8.t000644 000766 000024 00000001754 12563006275 016270 0ustar00etherstaff000000 000000 use utf8; use warnings; use strict; use Test::More; use Encode 2.21 'decode_utf8'; use File::Spec; { package MyApp::Controller::Root; $INC{'MyApp/Controller/Root.pm'} = __FILE__; use base 'Catalyst::Controller'; sub heart :Path('♥') { my ($self, $c) = @_; $c->stash(hearts=>'♥♥♥'); $c->detach('View::HTML'); } package MyApp::View::HTML; $INC{'MyApp/View/HTML.pm'} = __FILE__; use base 'Catalyst::View::TT'; MyApp::View::HTML->config( ENCODING => 'UTF-8', INCLUDE_PATH=> File::Spec->catfile('t')); package MyApp; use Catalyst; MyApp->setup; } use Catalyst::Test 'MyApp'; if(MyApp->can('encoding') and MyApp->can('clear_encoding') ) { ok my $res = request '/root/♥'; is $res->code, 200, 'OK'; is decode_utf8($res->content), "

This heart literal ♥

This is heart var ♥♥♥

\n", 'correct body'; is $res->content_charset, 'UTF-8'; } else { ok 1, 'Skipping the UTF8 Tests for older installed catalyst'; } done_testing; Catalyst-View-TT-0.44/t/root/heart000644 000766 000024 00000000102 12563006275 017210 0ustar00etherstaff000000 000000

This heart literal ♥

This is heart var [% hearts%]

Catalyst-View-TT-0.44/t/lib/TestApp/000755 000766 000024 00000000000 12604552454 017335 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp.pm000755 000766 000024 00000000704 12562667100 017675 0ustar00etherstaff000000 000000 package TestApp; use strict; use warnings; use Catalyst; # qw/-Debug/; use Path::Class; our $VERSION = '0.01'; __PACKAGE__->config( name => 'TestApp', default_message => 'hi', default_view => 'Pkgconfig', 'View::TT::Appconfig' => { PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', render_die => 1, }, ); __PACKAGE__->setup; Catalyst-View-TT-0.44/t/lib/TestApp/Controller/000755 000766 000024 00000000000 12604552454 021460 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/FauxProvider.pm000644 000766 000024 00000000636 12562667100 022314 0ustar00etherstaff000000 000000 package TestApp::FauxProvider; use Template::Constants; use base qw(Template::Provider); sub fetch { my $self = shift(); my $name = shift(); my $data = { name => $name, path => $name, text => 'Faux-tastic!', 'time' => time(), load => time() }; my ($page, $error) = $self->_compile($data); return ($page->{'data'}, $error); } 1;Catalyst-View-TT-0.44/t/lib/TestApp/Template/000755 000766 000024 00000000000 12604552454 021110 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/View/000755 000766 000024 00000000000 12604552454 020247 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/root/000755 000766 000024 00000000000 12604552454 020320 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/root/any_include_path/000755 000766 000024 00000000000 12604552454 023626 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/root/expose_methods.tt000644 000766 000024 00000000043 12562667100 023712 0ustar00etherstaff000000 000000 [% exposed_method('added param') %]Catalyst-View-TT-0.44/t/lib/TestApp/root/specified_template.tt000644 000766 000024 00000000055 12562667100 024515 0ustar00etherstaff000000 000000 I should be a [% param %] test in [% name %] Catalyst-View-TT-0.44/t/lib/TestApp/root/test.tt000644 000766 000024 00000000015 12562667100 021642 0ustar00etherstaff000000 000000 [% message %]Catalyst-View-TT-0.44/t/lib/TestApp/root/test_alt_content_type.tt000644 000766 000024 00000000015 12562667100 025275 0ustar00etherstaff000000 000000 [% message %]Catalyst-View-TT-0.44/t/lib/TestApp/root/test_include_path/000755 000766 000024 00000000000 12604552454 024016 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/root/test_include_path/testpath.tt000644 000766 000024 00000000016 12562667100 026216 0ustar00etherstaff000000 000000 [% message %] Catalyst-View-TT-0.44/t/lib/TestApp/root/any_include_path/test000644 000766 000024 00000000015 12562667100 024522 0ustar00etherstaff000000 000000 [% message %]Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/000755 000766 000024 00000000000 12604552454 020576 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/AltContentType.pm000755 000766 000024 00000000260 12562667100 024050 0ustar00etherstaff000000 000000 package TestApp::View::TT::AltContentType; use strict; use base 'Catalyst::View::TT'; __PACKAGE__->config( TEMPLATE_EXTENSION => '.tt', content_type => 'text/plain', ); Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Appconfig.pm000755 000766 000024 00000000126 12562667100 023042 0ustar00etherstaff000000 000000 package TestApp::View::TT::Appconfig; use strict; use base 'Catalyst::View::TT'; 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Classconfig.pm000644 000766 000024 00000000302 12562667100 023360 0ustar00etherstaff000000 000000 package TestApp::View::TT::Classconfig; use strict; use base 'Catalyst::View::TT'; use TestApp::Template::Any; __PACKAGE__->config( CLASS => 'TestApp::Template::Any', ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Encoding.pm000644 000766 000024 00000000767 12562667100 022672 0ustar00etherstaff000000 000000 package TestApp::View::TT::Encoding; use strict; use base 'Catalyst::View::TT'; __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', 'TEMPLATE_EXTENSION' => '.tt', 'DEFAULT_ENCODING' => 'utf-8', PROVIDERS => [ { name => 'Encoding', copy_config => [qw(INCLUDE_PATH DEFAULT_ENCODING PRE_CHOMP POST_CHOMP)] } ], ) if eval { require Template::Provider::Encoding; }; 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/ExposeMethods.pm000644 000766 000024 00000000527 12562667100 023725 0ustar00etherstaff000000 000000 package TestApp::View::TT::ExposeMethods; use Moose; extends 'Catalyst::View::TT'; __PACKAGE__->config( expose_methods => [q/exposed_method/], ); sub exposed_method { my ($self, $c, $some_param) = @_; unless ($some_param) { Catalyst::Exception->throw( "no param passed" ); } return 'magic ' . $some_param; } 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/ExposeMethodsSubclassed.pm000644 000766 000024 00000000160 12562667100 025727 0ustar00etherstaff000000 000000 package TestApp::View::TT::ExposeMethodsSubclassed; use Moose; extends 'TestApp::View::TT::ExposeMethods'; 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Includepath.pm000644 000766 000024 00000000546 12562667100 023377 0ustar00etherstaff000000 000000 package TestApp::View::TT::Includepath; use FindBin; use Path::Class; use strict; use base 'Catalyst::View::TT'; my $includepath = dir($FindBin::Bin, '/lib/TestApp/root/test_include_path'); __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', INCLUDE_PATH => "aaa:$includepath", ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Includepath2.pm000644 000766 000024 00000000541 12562667100 023454 0ustar00etherstaff000000 000000 package TestApp::View::TT::Includepath2; use FindBin; use Path::Class; use strict; use base 'Catalyst::View::TT'; my $includepath = dir($FindBin::Bin, '/lib/TestApp/root/test_include_path'); __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', INCLUDE_PATH => $includepath, ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Includepath3.pm000644 000766 000024 00000000566 12562667100 023464 0ustar00etherstaff000000 000000 package TestApp::View::TT::Includepath3; use FindBin; use Path::Class; use strict; use base 'Catalyst::View::TT'; our @include_path; my $includepath = dir($FindBin::Bin, '/lib/TestApp/root/test_include_path'); __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', INCLUDE_PATH => \@include_path, ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Pkgconfig.pm000755 000766 000024 00000000312 12562667100 023040 0ustar00etherstaff000000 000000 package TestApp::View::TT::Pkgconfig; use strict; use base 'Catalyst::View::TT'; __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/View/TT/Providerconfig.pm000644 000766 000024 00000000651 12562667100 024114 0ustar00etherstaff000000 000000 package TestApp::View::TT::Providerconfig; use strict; use base 'Catalyst::View::TT'; __PACKAGE__->config( PRE_CHOMP => 1, POST_CHOMP => 1, TEMPLATE_EXTENSION => '.tt', PROVIDERS => [ { name => '+TestApp::FauxProvider', args => {} }, # { # name => '_file_', # args => {} # } ] ); 1; Catalyst-View-TT-0.44/t/lib/TestApp/Template/Any.pm000644 000766 000024 00000000635 12562667100 022177 0ustar00etherstaff000000 000000 use strict; use warnings; package TestApp::Template::Any; use base 'Template'; use FindBin; use Path::Class; sub new { my $class = shift; my $params = defined($_[0]) && ref($_[0]) eq 'HASH' ? shift : {@_}; my $includepath = dir($FindBin::Bin, '/lib/TestApp/root/any_include_path'); $params->{INCLUDE_PATH} = $includepath; return $class->SUPER::new( $params ); } 1; Catalyst-View-TT-0.44/t/lib/TestApp/Controller/Root.pm000644 000766 000024 00000004206 12562667100 022741 0ustar00etherstaff000000 000000 package TestApp::Controller::Root; use base 'Catalyst::Controller'; __PACKAGE__->config(namespace => ''); sub default : Private { my ($self, $c) = @_; $c->response->redirect($c->uri_for('test')); } sub test : Local { my ($self, $c) = @_; $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message}); $c->stash->{template} = $c->request->param('template'); } sub test_includepath : Local { my ($self, $c) = @_; $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message}); $c->stash->{template} = $c->request->param('template'); if ( $c->request->param('additionalpath') ){ my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('additionalpath')); $c->stash->{additional_template_paths} = ["$additionalpath"]; } if ( $c->request->param('addpath') ){ my $additionalpath = Path::Class::dir($c->config->{root}, $c->request->param('addpath')); my $view = 'TestApp::View::TT::' . ($c->request->param('view') || $c->config->{default_view}); no strict "refs"; push @{$view . '::include_path'}, "$additionalpath"; use strict; } } sub test_render : Local { my ($self, $c) = @_; $c->stash->{message} = eval { $c->view('TT::Appconfig')->render($c, $c->req->param('template'), {param => $c->req->param('param') || ''}) }; if (my $err = $@) { $c->response->body($err); $c->response->status(403); } else { $c->stash->{template} = 'test.tt'; } } sub test_msg : Local { my ($self, $c) = @_; my $tmpl = $c->req->param('msg'); $c->stash->{message} = $c->view('TT::Appconfig')->render($c, \$tmpl); $c->stash->{template} = 'test.tt'; } sub test_alt_content_type : Local { my ($self, $c) = @_; $c->stash( message => 'test_alt_content_type'); $c->forward('View::TT::AltContentType'); } sub end : Private { my ($self, $c) = @_; return 1 if $c->response->status =~ /^3\d\d$/; return 1 if $c->response->body; my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view}); $c->forward($view); } 1; Catalyst-View-TT-0.44/maint/Makefile.PL.include000644 000766 000024 00000000445 12563012701 021441 0ustar00etherstaff000000 000000 use strict; use warnings; BEGIN { -e 'Distar' or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git") } use lib 'Distar/lib'; use Distar; manifest_include( 't/lib' => '.tt', 't/lib' => 'test', 't/root' => 'heart', ); 1; # vim: set ft=perl ts=8 sts=4 sw=4 tw=115 et : Catalyst-View-TT-0.44/lib/Catalyst/000755 000766 000024 00000000000 12604552454 017276 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/lib/Catalyst/Helper/000755 000766 000024 00000000000 12604552454 020515 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/lib/Catalyst/View/000755 000766 000024 00000000000 12604552454 020210 5ustar00etherstaff000000 000000 Catalyst-View-TT-0.44/lib/Catalyst/View/TT.pm000644 000766 000024 00000061153 12604551611 021075 0ustar00etherstaff000000 000000 package Catalyst::View::TT; use strict; use warnings; use base qw/Catalyst::View/; use Data::Dump 'dump'; use Template; use Template::Timer; use MRO::Compat; use Scalar::Util qw/blessed weaken/; our $VERSION = '0.44'; $VERSION = eval $VERSION; __PACKAGE__->mk_accessors('template'); __PACKAGE__->mk_accessors('expose_methods'); __PACKAGE__->mk_accessors('include_path'); __PACKAGE__->mk_accessors('content_type'); *paths = \&include_path; =head1 NAME Catalyst::View::TT - Template View Class =head1 SYNOPSIS # use the helper to create your View myapp_create.pl view Web TT # add custom configuration in View/Web.pm __PACKAGE__->config( # any TT configuration items go here TEMPLATE_EXTENSION => '.tt', CATALYST_VAR => 'c', TIMER => 0, ENCODING => 'utf-8' # Not set by default PRE_PROCESS => 'config/main', WRAPPER => 'site/wrapper', render_die => 1, # Default for new apps, see render method docs expose_methods => [qw/method_in_view_class/], ); # add include path configuration in MyApp.pm __PACKAGE__->config( 'View::Web' => { INCLUDE_PATH => [ __PACKAGE__->path_to( 'root', 'src' ), __PACKAGE__->path_to( 'root', 'lib' ), ], }, ); # render view from lib/MyApp.pm or lib/MyApp::Controller::SomeController.pm sub message : Global { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->stash->{message} = 'Hello World!'; $c->forward( $c->view('Web') ); } # access variables from template The message is: [% message %]. # example when CATALYST_VAR is set to 'Catalyst' Context is [% Catalyst %] The base is [% Catalyst.req.base %] The name is [% Catalyst.config.name %] # example when CATALYST_VAR isn't set Context is [% c %] The base is [% base %] The name is [% name %] =cut sub _coerce_paths { my ( $paths, $dlim ) = shift; return () if ( !$paths ); return @{$paths} if ( ref $paths eq 'ARRAY' ); # tweak delim to ignore C:/ unless ( defined $dlim ) { $dlim = ( $^O eq 'MSWin32' ) ? ':(?!\\/)' : ':'; } return split( /$dlim/, $paths ); } sub new { my ( $class, $c, $arguments ) = @_; my $config = { EVAL_PERL => 0, TEMPLATE_EXTENSION => '', CLASS => 'Template', %{ $class->config }, %{$arguments}, }; if ( ! (ref $config->{INCLUDE_PATH} eq 'ARRAY') ) { my $delim = $config->{DELIMITER}; my @include_path = _coerce_paths( $config->{INCLUDE_PATH}, $delim ); if ( !@include_path ) { my $root = $c->config->{root}; my $base = Path::Class::dir( $root, 'base' ); @include_path = ( "$root", "$base" ); } $config->{INCLUDE_PATH} = \@include_path; } # if we're debugging and/or the TIMER option is set, then we install # Template::Timer as a custom CONTEXT object, but only if we haven't # already got a custom CONTEXT defined if ( $config->{TIMER} ) { if ( $config->{CONTEXT} ) { $c->log->error( 'Cannot use Template::Timer - a TT CONTEXT is already defined' ); } else { $config->{CONTEXT} = Template::Timer->new(%$config); } } if ( $c->debug && $config->{DUMP_CONFIG} ) { $c->log->debug( "TT Config: ", dump($config) ); } my $self = $class->next::method( $c, { %$config }, ); # Set base include paths. Local'd in render if needed $self->include_path($config->{INCLUDE_PATH}); $self->expose_methods($config->{expose_methods}); $self->config($config); # Creation of template outside of call to new so that we can pass [ $self ] # as INCLUDE_PATH config item, which then gets ->paths() called to get list # of include paths to search for templates. # Use a weakened copy of self so we don't have loops preventing GC from working my $copy = $self; Scalar::Util::weaken($copy); $config->{INCLUDE_PATH} = [ sub { $copy->paths } ]; if ( $config->{PROVIDERS} ) { my @providers = (); if ( ref($config->{PROVIDERS}) eq 'ARRAY') { foreach my $p (@{$config->{PROVIDERS}}) { my $pname = $p->{name}; my $prov = 'Template::Provider'; if($pname eq '_file_') { $p->{args} = { %$config }; } else { if($pname =~ s/^\+//) { $prov = $pname; } else { $prov .= "::$pname"; } # We copy the args people want from the config # to the args $p->{args} ||= {}; if ($p->{copy_config}) { map { $p->{args}->{$_} = $config->{$_} } grep { exists $config->{$_} } @{ $p->{copy_config} }; } } local $@; eval "require $prov"; if(!$@) { push @providers, "$prov"->new($p->{args}); } else { $c->log->warn("Can't load $prov, ($@)"); } } } delete $config->{PROVIDERS}; if(@providers) { $config->{LOAD_TEMPLATES} = \@providers; } } $self->{template} = $config->{CLASS}->new($config) || do { my $error = $config->{CLASS}->error(); $c->log->error($error); $c->error($error); return undef; }; return $self; } sub process { my ( $self, $c ) = @_; my $template = $c->stash->{template} || $c->action . $self->config->{TEMPLATE_EXTENSION}; unless (defined $template) { $c->log->debug('No template specified for rendering') if $c->debug; return 0; } local $@; my $output = eval { $self->render($c, $template) }; if (my $err = $@) { return $self->_rendering_error($c, $template . ': ' . $err); } if (blessed($output) && $output->isa('Template::Exception')) { $self->_rendering_error($c, $output); } unless ( $c->response->content_type ) { my $default = $self->content_type || 'text/html; charset=UTF-8'; $c->response->content_type($default); } $c->response->body($output); return 1; } sub _rendering_error { my ($self, $c, $err) = @_; my $error = qq/Couldn't render template "$err"/; $c->log->error($error); $c->error($error); return 0; } sub render { my ($self, $c, $template, $args) = @_; $c->log->debug(qq/Rendering template "$template"/) if $c && $c->debug; my $output; my $vars = { (ref $args eq 'HASH' ? %$args : %{ $c->stash() }), $self->template_vars($c) }; local $self->{include_path} = [ @{ $vars->{additional_template_paths} }, @{ $self->{include_path} } ] if ref $vars->{additional_template_paths}; unless ( $self->template->process( $template, $vars, \$output ) ) { if (exists $self->{render_die}) { die $self->template->error if $self->{render_die}; return $self->template->error; } $c->log->debug('The Catalyst::View::TT render() method will start dying on error in a future release. Unless you are calling the render() method manually, you probably want the new behaviour, so set render_die => 1 in config for ' . blessed($self) . '. If you wish to continue to return the exception rather than throwing it, add render_die => 0 to your config.') if $c && $c->debug; return $self->template->error; } return $output; } sub template_vars { my ( $self, $c ) = @_; return () unless $c; my $cvar = $self->config->{CATALYST_VAR}; my %vars = defined $cvar ? ( $cvar => $c ) : ( c => $c, base => $c->req->base, name => $c->config->{name} ); if ($self->expose_methods) { my $meta = $self->meta; foreach my $method_name (@{$self->expose_methods}) { my $method = $meta->find_method_by_name( $method_name ); unless ($method) { Catalyst::Exception->throw( "$method_name not found in TT view" ); } my $method_body = $method->body; my $weak_ctx = $c; weaken $weak_ctx; my $sub = sub { $self->$method_body($weak_ctx, @_); }; $vars{$method_name} = $sub; } } return %vars; } 1; __END__ =head1 DESCRIPTION This is the Catalyst view class for the L