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 '' if $method eq 'DESTROY';
34 if (!$presenter->can($method)) {
35 $::lxdebug->message(LXDebug::WARN(), "SL::Presenter has no method named '$method'!");
39 splice @args, -1, 1, %{ $args[-1] } if @args && (ref($args[-1]) eq 'HASH');
41 $presenter->$method(@args);
54 SL::Template::Plugin::P - Template plugin for the presentation layer
60 Customer: [% P.customer(customer) %]
63 [% P.grouped_record_list(RECORDS) %]
71 All unknown functions called on C<P> are forwarded to functions with
72 the same name in the global presenter object.
74 The presenter's functions use hashes for named-argument
75 passing. Unfortunately L<Template> groups named arguments into hash
76 references. This makes mixing intentional hash references and named
77 arguments a bit hairy. For example, the following calls from a
78 template are undistinguishable for a plugin:
80 [% P.some_func({ arg1 => 42, arg2 => 'Charlie' }) %]
81 [% P.some_func(arg1 => 42, arg2 => 'Charlie') %]
82 [% P.some_func(arg1=42, arg2='Charlie') %]
83 [% P.some_func(arg1=42, arg2='Charlie') %]
85 C<AUTOLOAD> tries to be clever and unpacks a hash reference into a
86 normal hash if and only if it is the very last parameter to the
89 Returns the result of the corresponding function in the presenter.
93 Returns an HTML-escaped version of C<$text>. Instead of a string an
94 instance of the thin proxy-object L<SL::Presenter::EscapedText> is
97 It is safe to call C<escape> on an instance of
98 L<SL::Presenter::EscapedText>. This is a no-op (the same instance will
109 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>