From e576b2e34fb9f0dbeeb72b1ee93ea2955bd7cf9e Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 14 Mar 2011 17:48:25 -0400 Subject: [PATCH] If the TT stuff loads CGI w/o -utf8, that "instance" (not really instance)... ... will compete with use CGI in EGCatloader.pm. Really. Normally I enjoy perl but the awful, horrendous, unspeakable black magic used in CGI.pm has given me a great deal of trouble today. Specifically, I could not really succeed in subclassing it. I had a kind of half success before, but I could only really replace methods in my subclass, but not call the methods unchanged from the original base class (CGI). This manifested in a bug where I had been using the query_string() method preserve search terms across some pages, but that method had stopped working since I introduced the CGI subclass. In an attempt to fix that, I discovered this document http://stein.cshl.org/WWW/CGI/#subclassing and tried the advice therein, and several variations thereof, but everything I produced caused mod_perl to consume memory until it keeled over from OOM. Finally, I discovered that I never really needed the subclass in the first place, so long as 'use CGI' with no module parameters doesn't happen in the same process as 'use CGI qw/-utf8/'. --- .../src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm | 6 +-- Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm | 2 +- .../src/perlmods/lib/OpenILS/WWW/EGWeb/CGI_utf8.pm | 44 ++++++++++++++++++++ .../web/templates/default/opac/parts/header.tt2 | 2 +- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGI_utf8.pm diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm index 178f4d8..ebfbbec 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm @@ -13,7 +13,7 @@ use OpenILS::Application::AppUtils; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Fieldmapper; use DateTime::Format::ISO8601; -use CGI qw(-utf8); +use CGI qw(:all -utf8); # EGCatLoader sub-modules use OpenILS::WWW::EGCatLoader::Util; @@ -35,10 +35,6 @@ sub new { $self->ctx($ctx); $self->cgi(new CGI); - my $msg1 = "LFW XXX: param('query') is " . $self->cgi->param('query'); - $logger->info("LFW XXX: msg1 is " . $msg1); - $logger->info("LFW XXX: query_string is " . $self->cgi->query_string()); - OpenILS::Utils::CStoreEditor->init; # just in case $self->editor(new_editor()); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm index 6a7f49a..67e419d 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm @@ -53,7 +53,7 @@ sub handler { DEBUG => $ctx->{debug_template}, PLUGINS => { EGI18N => 'OpenILS::WWW::EGWeb::I18NFilter', - CGIUTF8 => 'OpenILS::WWW::EGWeb::CGIUTF8' + CGI_utf8 => 'OpenILS::WWW::EGWeb::CGI_utf8' } }); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGI_utf8.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGI_utf8.pm new file mode 100644 index 0000000..0239e1b --- /dev/null +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb/CGI_utf8.pm @@ -0,0 +1,44 @@ +package OpenILS::WWW::EGWeb::CGI_utf8; + +# The code in this module is copied from (except for a tiny modification) +# Template::Plugin::CGI, which is written by: +# +# Andy Wardley Eabw@wardley.orgE L +# +# Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. +# +# This module is free software; you can redistribute it and/or +# modify it under the same terms as Perl itself. + +use strict; +use warnings; +use base 'Template::Plugin'; +use CGI qw(:all -utf8); + +sub new { + my $class = shift; + my $context = shift; + new CGI(@_); +} + +# monkeypatch CGI::params() method to Do The Right Thing in TT land + +sub CGI::params { + my $self = shift; + local $" = ', '; + + return $self->{ _TT_PARAMS } ||= do { + # must call Vars() in a list context to receive + # plain list of key/vals rather than a tied hash + my $params = { $self->Vars() }; + + # convert any null separated values into lists + @$params{ keys %$params } = map { + /\0/ ? [ split /\0/ ] : $_ + } values %$params; + + $params; + }; +} + +1; diff --git a/Open-ILS/web/templates/default/opac/parts/header.tt2 b/Open-ILS/web/templates/default/opac/parts/header.tt2 index 29a938f..069dbef 100644 --- a/Open-ILS/web/templates/default/opac/parts/header.tt2 +++ b/Open-ILS/web/templates/default/opac/parts/header.tt2 @@ -1,6 +1,6 @@ [%- USE money = format(l('$%.2f')); USE date; - USE CGI; + USE CGI = CGI_utf8; USE EGI18N; SET DATE_FORMAT = l('%m/%d/%Y'); -- 1.7.2.5