Template::Filters::LazyLoader

http://d.hatena.ne.jp/kopug/20061224/1166952067

id:kopug の方がTemplate::Filters::LazyLoaderをCatalystで使用の方法を上げてくれているので、負けじとUP。id:kopugさん、cpanに上げようと思ってたんだけど、なかなか忙しくてさ。今度Offの時に一緒にコーディングでもしましょうよ。

package Catalyst::View::TT::Filters::LazyLoader;

use strict;
use base qw(Catalyst::View::TT);
use Template::Filters::LazyLoader;

our $VERSION = '1.0';

sub new {
    my ($class, $c, $arguments) = @_;

    my $lazy = Template::Filters::LazyLoader->new();
    $lazy->base_pkg( $c->config->{template_filters_lazyloader}{base_pkg} );

    if ( defined $c->config->{template_filters_lazyloader}{static_filter_prefix} ) {
        $lazy->static_filter_prefix( $c->config->{template_filters_lazyloader}{static_filter_prefix} ) 
    }
    if ( defined $c->config->{template_filters_lazyloader}{dynamic_filter_prefix} ) {
        $lazy->dynamic_filter_prefix( $c->config->{template_filters_lazyloader}{dynamic_filter_prefix} ) 
    }

    if ( defined $c->config->{template_filters_lazyloader}{lib_path} ) {
        $lazy->lib_path( $c->config->{template_filters_lazyloader}{lib_path} );
    }

    $arguments->{FILTERS} = $lazy->load() ;
    my $self = $class->SUPER::new($c, $arguments);
    return $self ;

}

1;

=head1 NAME

Catalyst::View::TT::Filters::LazyLoader - TT View Class with Template::Filters::LazyLoader support.

=head1 SYNOPSYS

 package MyApp::View::TT;
 
 use strict;
 use base 'Catalyst::View::TT::Filters::LazyLoader';
 

my_app.yml
 ---
 name : MyApp
 template_filters_lazyloader :
    base_pkg : MyApp::TT::Filters
# Option
    static_filter_prefix  : fs_
    dynamic_filter_prefix : ds_
    lib_path              : /tmp/lib

=head1 SEE ALSO

 L<Template::Filters::LazyLoader>

=head1 AUTHOR

Tomohiro Teranishi E<lt>tomohiro.teranishi at gmail.comE<gt>

=cut