1 package SL::Template::Plugin::P;
 
   3 use base qw( Template::Plugin );
 
   6 use SL::Presenter::EscapedText;
 
  11   my ($class, $context, @args) = @_;
 
  19   my ($self, $string) = @_;
 
  20   return SL::Presenter::EscapedText->new(text => $string);
 
  26   my ($self, @args) = @_;
 
  28   my $presenter     = SL::Presenter->get;
 
  29   my $method        =  $AUTOLOAD;
 
  32   return '' unless $presenter->can($method);
 
  34   splice @args, -1, 1, %{ $args[-1] } if @args && (ref($args[-1]) eq 'HASH');
 
  36   $presenter->$method(@args);
 
  49 SL::Template::Plugin::P - Template plugin for the presentation layer
 
  55   Customer: [% P.customer(customer) %]
 
  58   [% P.grouped_record_list(RECORDS) %]
 
  66 All unknown functions called on C<P> are forwarded to functions with
 
  67 the same name in the global presenter object.
 
  69 The presenter's functions use hashes for named-argument
 
  70 passing. Unfortunately L<Template> groups named arguments into hash
 
  71 references. This makes mixing intentional hash references and named
 
  72 arguments a bit hairy. For example, the following calls from a
 
  73 template are undistinguishable for a plugin:
 
  75   [% P.some_func({ arg1 => 42, arg2 => 'Charlie' }) %]
 
  76   [% P.some_func(arg1 => 42, arg2 => 'Charlie') %]
 
  77   [% P.some_func(arg1=42, arg2='Charlie') %]
 
  78   [% P.some_func(arg1=42, arg2='Charlie') %]
 
  80 C<AUTOLOAD> tries to be clever and unpacks a hash reference into a
 
  81 normal hash if and only if it is the very last parameter to the
 
  84 Returns the result of the corresponding function in the presenter.
 
  88 Returns an HTML-escaped version of C<$text>. Instead of a string an
 
  89 instance of the thin proxy-object L<SL::Presenter::EscapedText> is
 
  92 It is safe to call C<escape> on an instance of
 
  93 L<SL::Presenter::EscapedText>. This is a no-op (the same instance will
 
 104 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>