1 package SL::Template::Plugin::P;
3 use base qw( Template::Plugin );
6 use SL::Presenter::ALL;
7 use SL::Presenter::Simple;
8 use SL::Presenter::EscapedText;
13 my ($class, $context, @args) = @_;
21 my ($self, $string) = @_;
22 return SL::Presenter::EscapedText->new(text => $string);
28 my ($self, @args) = @_;
29 my $presenter = SL::Presenter->get;
30 my $method = $AUTOLOAD;
33 return '' if $method eq 'DESTROY';
35 splice @args, -1, 1, %{ $args[-1] } if @args && (ref($args[-1]) eq 'HASH');
37 if ($SL::Presenter::ALL::presenters{$method}) {
38 return SL::Presenter::ALL::wrap($SL::Presenter::ALL::presenters{$method});
41 if (my $sub = SL::Presenter::Simple->can($method)) {
45 if ($presenter->can($method)) {
46 return $presenter->$method(@args);
49 $::lxdebug->message(LXDebug::WARN(), "SL::Presenter has no method named '$method'!");
63 SL::Template::Plugin::P - Template plugin for the presentation layer
69 Customer: [% customer.presenter.customer %]
72 [% P.record.grouped_list(RECORDS) %]
80 All unknown functions called on C<P> are forwarded to functions with
81 the same name in the global presenter object.
83 The presenter's functions use hashes for named-argument
84 passing. Unfortunately L<Template> groups named arguments into hash
85 references. This makes mixing intentional hash references and named
86 arguments a bit hairy. For example, the following calls from a
87 template are undistinguishable for a plugin:
89 [% P.some_func({ arg1 => 42, arg2 => 'Charlie' }) %]
90 [% P.some_func(arg1 => 42, arg2 => 'Charlie') %]
91 [% P.some_func(arg1=42, arg2='Charlie') %]
92 [% P.some_func(arg1=42, arg2='Charlie') %]
94 C<AUTOLOAD> tries to be clever and unpacks a hash reference into a
95 normal hash if and only if it is the very last parameter to the
98 Returns the result of the corresponding function in the presenter.
100 =item C<escape $text>
102 Returns an HTML-escaped version of C<$text>. Instead of a string an
103 instance of the thin proxy-object L<SL::Presenter::EscapedText> is
106 It is safe to call C<escape> on an instance of
107 L<SL::Presenter::EscapedText>. This is a no-op (the same instance will
118 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>