Template::Filters::LazyLoader - Loading template filter modules by lazy way.
Are you lazy? If so you come to right place :-) . This module load all your nice and sexy custom template filter modules with very simple and lazy way.
What you need to do is set parent package and then, LazyLoader read all packages recursively under the parent package and read all filter modules automatically from those packages.
my $lazy = Template::Filters::LazyLoader->new(); # You must use base_pkg or pkg , do not use both. # Case using base_pkg # read all packages which using My::Custom::Filters as base module . # e.g. ( My::Custom::Filters::One , My::Custom::Filters::Two , # My::Custom::Filters::A::Three ... ) $lazy->base_pkg('My::Custom::Filters'); # case using pkg # read My::Custom::Filter package only. $lazy->pkg( 'My::Custom::Filter'); # case using pkgs $lazy->pkgs( [qw/My::Filter1 My::Filter2/] ); # below methods are optional. I never use it. #$lazy->static_filter_prefix( 'fs_' ); # default is fs_ #$laxy->dynamic_filter_prefix( fd_' ); # default is fd_ #$lazy->lib_path( '/path/to/your/lib') # default is $INC[0] my $tt = Template->new( { FILTERS => $lazy->load() ); # $lazy->filters();
Your one filter package.
package Your::Filter::OK; sub fs_foo { return 'foo'; } sub fd_boo { sub { return 'boo'; } }
Your template
[% 'I never show up | foo %] [% FILTER boo( 1,32,4,3) %] orz [% END %]
This is the example where you put your filter package.
Suppose you set base_pkg as 'CustomFilters' and you have below lib tree.
|-- lib | |-- CustomFilters | | |-- Osaka.pm | | |-- Seattle.pm | | `-- USA | | `-- Okurahoma.pm | |-- CustomFilters.pm | `-- NeverCalled.pm
LazyLoader only read under CustomFilters dir recursively means it does not read CustomFilters.pm and NeverCalled.pm
You must read 'Configuration - Plugins and Filters' SECTION for Template Tool Document first.
OK now you know there are 2 types of filter which are static and dynamic. To distinct between this , LazyLoader ask you to set prefix for your all filter methods. for static you should start your method with 'fs_' and for dynamic 'fd_'. You can also change this prefix with static_filter_prefix , dynamic_filter_prefix methods if you want.
sub fs_foo{ return 'foo'; } sub fd_bar{ return sub { return 'bar'; } } sub never_loaded { return "This module never read by LazyLoader"; }
There is very important rule to use LazyLoader. Method name must be unique even different package.
sub {prefix}must_unique_name { }
set your parent package!!!
set your package which contain filter modules.
set your pakcages as array ref.
Load your filter modules and return filters hash ref.
return filters hash ref. You must use this after calling load() method.
You can set static filter prefix if you want. default is 'fs_'
You can set dynamic filter prefix if you want. default is 'fd_'
You can set lib path if you want. default if $INC[0] SEE Module::Recursive::Require
Module::Recursive::Require
Template , Class::Accessor::Fast , Module::Recursive::Require
Tomohiro Teranishi <tomohiro.teranishi+cpan@gmail.com>
This program is distributed under the Artistic License
To install Template::Filters::LazyLoader, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Filters::LazyLoader
CPAN shell
perl -MCPAN -e shell install Template::Filters::LazyLoader
For more information on module installation, please visit the detailed CPAN module installation guide.