From: Bill Erickson Date: Mon, 1 Aug 2011 13:00:30 +0000 (-0400) Subject: Bypass install_filter mem leak via direct insertion X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=efce5923f0817b85848d73a92a5a9495c1bcabf1;p=evergreen%2Fpines.git Bypass install_filter mem leak via direct insertion See https://rt.cpan.org/Ticket/Display.html?id=46691 On the one hand we have a memory leak, on the other we have a bug caused by the fix to the memory leak. Bypass this altogether and insert the filter manually into the template environment using Template's FILTER configuration argument. This has the added bonus of simplifying the i18n filter code. Since the filter is manually inserted, it's not necessary (and possibly counter-productive) to USE the filter directly in the template. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 922f7e18c7..d684ad04fd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -47,6 +47,8 @@ sub handler { $template = $ctx->{skin} . "/$template"; + my $text_handler = set_text_handler($ctx, $r); + my $tt = Template->new({ OUTPUT => ($as_xml) ? sub { parse_as_xml($r, $ctx, @_); } : $r, INCLUDE_PATH => $ctx->{template_paths}, @@ -54,10 +56,11 @@ sub handler { PLUGINS => { EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter', CGI_utf8 => 'OpenILS::WWW::EGWeb::CGI_utf8' - } + }, + FILTERS => {l => $text_handler} }); - unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => set_text_handler($ctx, $r)})) { + unless($tt->process($template, {ctx => $ctx, ENV => \%ENV, l => $text_handler})) { $r->log->warn('egweb: template error: ' . $tt->error); return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; } @@ -79,8 +82,7 @@ sub set_text_handler { $lh_cache{$locale} = $lh_cache{'en_US'}; } - return $OpenILS::WWW::EGWeb::I18NFilter::maketext = - sub { return $lh_cache{$locale}->maketext(@_); }; + return sub { return $lh_cache{$locale}->maketext(@_); }; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm index cc931fa59f..6b6c6a8b63 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/I18NFilter.pm @@ -2,18 +2,11 @@ package OpenILS::WWW::EGWeb::I18NFilter; use Template::Plugin::Filter; use base qw(Template::Plugin::Filter); our $DYNAMIC = 1; -our $maketext; sub filter { my ($self, $text, $args) = @_; return $maketext->($text, @$args); } -sub init { - my $self = shift; - $self->install_filter('l'); - return $self; -} - 1; diff --git a/Open-ILS/web/templates/default/opac/parts/header.tt2 b/Open-ILS/web/templates/default/opac/parts/header.tt2 index 581307dc0d..f906e56515 100644 --- a/Open-ILS/web/templates/default/opac/parts/header.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/header.tt2 @@ -1,7 +1,6 @@ [%- USE money = format(l('$%.2f')); USE date; USE CGI = CGI_utf8; - USE EGI18N; USE POSIX; SET DATE_FORMAT = l('%m/%d/%Y');