+ my %params = ( %locals,
+ AUTH => $::auth,
+ FORM => $::form,
+ LOCALE => $::locale,
+ LXCONFIG => { dbcharset => $::dbcharset,
+ webdav => $::webdav,
+ lizenzen => $::lizenzen,
+ latex_templates => $::latex,
+ opendocument_templates => $::opendocument_templates,
+ vertreter => $::vertreter,
+ show_best_before => $::show_best_before,
+ },
+ LXDEBUG => $::lxdebug,
+ MYCONFIG => \%::myconfig,
+ SELF => $self,
+ );
+
+ my $output;
+ my $parser = $self->_template_obj;
+ $parser->process($source, \%params, \$output) || croak $parser->error;
+
+ print $output unless $options->{inline};
+
+ return $output;
+}
+
+#
+# Before/after run hooks
+#
+
+sub run_before {
+ _add_hook('before', @_);
+}
+
+sub run_after {
+ _add_hook('after', @_);
+}
+
+my %hooks;
+
+sub _add_hook {
+ my ($when, $class, $sub, %params) = @_;
+
+ foreach my $key (qw(only except)) {
+ $params{$key} = { map { ( $_ => 1 ) } @{ $params{$key} } } if $params{$key};
+ }
+
+ my $idx = "${when}/${class}";
+ $hooks{$idx} ||= [ ];
+ push @{ $hooks{$idx} }, { %params, code => $sub };
+}
+
+sub _run_hooks {
+ my ($self, $when, $action) = @_;
+
+ my $idx = "${when}/" . ref($self);
+
+ foreach my $hook (@{ $hooks{$idx} || [] }) {
+ next if ($hook->{only } && !$hook->{only }->{$action})
+ || ($hook->{except} && $hook->{except}->{$action});
+
+ if (ref($hook->{code}) eq 'CODE') {
+ $hook->{code}->($self);
+ } else {
+ my $sub = $hook->{code};
+ $self->$sub;
+ }
+ }