NAME

Template::Filters::LazyLoader - Loading template filter modules by lazy way.

DESCRIPTION

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.

SYNOPSYS

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');

# 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 %]

SET BASE PACKAGE

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

SET PREFIX

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";
}

NAMING RULE

There is very important rule to use LazyLoader. Method name must be unique even different package.

sub {prefix}must_unique_name {

}

METHOD

base_pkg

set your parent package!!!

pkg

set your package which contain filter modules.

load

Load your filter modules and return filters hash ref.

filters

return filters hash ref. You must use this after calling load() method.

static_filter_prefix

You can set static filter prefix if you want. default is 'fs_'

dynamic_filter_prefix

You can set dynamic filter prefix if you want. default is 'fd_'

lib_path

You can set lib path if you want. default if $INC[0] SEE Module::Recursive::Require

SEE ALSO

Template , Class::Accessor::Fast , Module::Recursive::Require

AUTHOR

Tomohiro Teranishi <tomohiro.teranishi+cpan@gmail.com>

COPYRIGHT

This program is distributed under the Artistic License