The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Egg::Plugin::TemplateAuto - Plugin in which it assists for template decision.

SYNOPSIS

  use Egg qw/ TemplateAuto /;
  
  __PACKAGE__->egg_startup(
    .......
    .....
    template_path        => ['<$e.template>', '<$e.comp>'],
    template_extension   => 'tt',
    plugin_template_auto => { ignore_names=> [qw/index/] },
    );
  
  __PACKAGE__->dispatch_map(
    .......
    .....
    hoge => {
      .....
      qr{^([a-zA-Z0-9]+)}=> sub {
        my($e, $dispatch, $parts)= @_;
        $e->template_auto('/hoge/', $parts->[0]);
        },
      },
    );

DESCRIPTION

This plugin decides the template based on the character string acquired from the action that matches to the regular expression of dispatch_map.

  __PACKAGE__->dispatch_map(
    .......
    qr{^(.+)}=> sub { $_[0]->template_auto('/boo/', $_[2]->[0]) },
    );

* Time when dispatch is set every time TEMPLETE is added can be saved by setting the match rule like the example above at the route level of dispatch. However, it is recommended to write dispatch lowered by one step whether to write the regular expression to match it by a certain format to set the code in which something is done separately because it embarrasses it if it matches it for everything.

  __PACKAGE__->dispatch_map(
    .......
    wanko => \&wanko,
    qr{^([A-Z][a-z0-9]+)}=> sub { $_[0]->template_auto('/boo/', $_[2]->[0]) },
    hoge => sub {
      qr{^(.+)}=> sub { $_[0]->template_auto('/hoge/', $_[2]->[0]) },
      },
    );

When a suitable template is not found from the directory set to 'template_path', $e->finished(404) is set. * 404 Not Found.

CONFIGURATION

This plugin is set by 'Plugin_template_auto'.

Additionally, refer to 'template_path' and 'template_extension' of root configuration.

ignore_names => [ARRAY]

When the template is decided by the set name, '404 Not Found' is returned.

  plugin_template_auto => {
    ignore_names => [qw/ index default /],
    },

base_dir => [SCALAR]

When BASE_DIR passed to the template_auto method is omitted, this setting is always used.

  plugin_template_auto => {
    base_dir => '/hoge/',
    },

METHODS

template_auto ([BASE_DIR], [TEMPLATE_NAME])

When BASE_DIR is omitted, a target template is processed right under 'template_path' assuming that it exists.

  $e->template_auto('/hoge/', 'nyanko');
  #
  #  /hoge/nyanko.tt returns to this.
  #

Please do not apply '/' to the head of BASE_DIR if it is unpalatable when there is '/' on the head of the template name when HTML::Template etc. are used.

  $e->template_auto('hoge/abc/', 'eteko');
  #
  #  Hoge/abc/eteko.tt is restored to this.
  #

SEE ALSO

Egg::Release,

AUTHOR

Masatoshi Mizuno <lushe@cpan.org>

COPYRIGHT

Copyright (C) 2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.