Debian Codegraph @

README

raw
1 NAME
2 Template::Provider::FromDATA - Load templates from your __DATA__ section
3
4 SYNOPSIS
5 use Template;
6 use Template::Provider::FromDATA;
7
8 # Create the provider
9 my $provider = Template::Provider::FromDATA->new( {
10 CLASSES => __PACKAGE__
11 } );
12
13 # Add the provider to the config
14 my $template = Template->new( {
15 # ...
16 LOAD_TEMPLATES => [ $provider ]
17 } );
18
19 # Render a template
20 $template->process( 'mytemplate', { bar => 'Bar' } );
21
22 # ...and now the templates
23
24 __DATA__
25
26 __mytemplate__
27 Foo [% bar %]
28
29 __myothertemplate__
30 Baz, [% qux %]?
31
32 DESCRIPTION
33 This module allows you to store your templates inline with your code in
34 the "__DATA__" section. It will search any number of classes specified.
35
36 CAVEAT
37 If you have two templates with the same name, this module will not
38 understand the difference, it will simply return the first one found. If
39 you wish, you can specify a fully qualified template name by prefixing
40 the template with the module name (using "-" instead of "::" as a
41 namespace separator), adding a "/" to separate the module name from the
42 template name.
43
44 $template->process( 'My-Templates/mytemplate', { bar => 'Bar' } );
45
46 INSTALLATION
47 perl Makefile.PL
48 make
49 make test
50 make install
51
52 METHODS
53 new( \%OPTIONS )
54 Create a new instance of the provider. You can specify a list of classes
55 to be searched for templates via the "CLASSES" option. By omitting this
56 option it will search "main".
57
58 # defaults to 'main'
59 $provider = Template::Provider::FromDATA->new;
60
61 # look for templates in 'Foo'
62 $provider = Template::Provider::FromDATA->new( {
63 CLASSES => 'Foo'
64 } );
65
66 # look for templates in 'Foo::Bar' and 'Foo::Baz'
67 $provider = Template::Provider::FromDATA->new( {
68 CLASSES => [ 'Foo::Bar', 'Foo::Baz' ]
69 } );
70
71 By default, template data is lazy-loaded as they it is requested. If you
72 wish to load up all template data upon initializtion, you can use the
73 "PRELOAD" option.
74
75 $provider = Template::Provider::FromDATA->new( {
76 PRELOAD => 1
77 } );
78
79 _init( \%OPTIONS )
80 A subclassed method to handle the options passed to "new()".
81
82 fetch( $name )
83 This is a subclassed method that will load a template via "_fetch()" if
84 a non-reference argument is passed.
85
86 _load( $name )
87 Loads the template via the "get_file()" sub and sets some cache
88 information.
89
90 get_file( $class, $template )
91 This method searches through $class for a template named $template.
92 Returns the contents on success, undef on failure.
93
94 This function was mostly borrowed from Catalyst::Helper's "get_file"
95 function.
96
97 ACCESSORS
98 classes
99 An arrayref of the class names containing our templates.
100
101 cache
102 A hashref of file and template data.
103
104 AUTHOR
105 Brian Cassidy <[email protected]>
106
107 COPYRIGHT AND LICENSE
108 Copyright 2005-2012 by Brian Cassidy
109
110 This library is free software; you can redistribute it and/or modify it
111 under the same terms as Perl itself.
112