From 83f0c6a9aaf9bc520cef93b958d51a5d85e8999c Mon Sep 17 00:00:00 2001 From: Paul Seamons Date: Fri, 21 Jul 2006 00:00:00 +0000 Subject: [PATCH] CGI::Ex 2.06 --- Changes | 5 +++++ META.yml | 2 +- lib/CGI/Ex.pm | 2 +- lib/CGI/Ex/App.pm | 17 +++++++---------- lib/CGI/Ex/Auth.pm | 2 +- lib/CGI/Ex/Conf.pm | 2 +- lib/CGI/Ex/Dump.pm | 2 +- lib/CGI/Ex/Fill.pm | 2 +- lib/CGI/Ex/JSONDump.pm | 4 ++-- lib/CGI/Ex/Template.pm | 21 +++++---------------- lib/CGI/Ex/Template.pod | 5 ----- lib/CGI/Ex/Validate.pm | 2 +- t/9_jsondump_00_base.t | 5 ++++- 13 files changed, 30 insertions(+), 41 deletions(-) diff --git a/Changes b/Changes index 67f99ea..de56ae7 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +2.06 2006-07-21 + * Allow for JSONDump to swap --> to --"+"> + * Fix memory issue in App with closures + * Remove weak_copy routine from Template (memory issue) + 2.05 2006-07-19 * Allow for CGI::Ex to be compatible with Mandrake and Fedora mod_perl 2, as well as debian mod_perl2 and older mod_perl1. diff --git a/META.yml b/META.yml index b294eaa..5adf0c7 100644 --- a/META.yml +++ b/META.yml @@ -1,7 +1,7 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: CGI-Ex -version: 2.05 +version: 2.06 version_from: lib/CGI/Ex.pm installdirs: site requires: diff --git a/lib/CGI/Ex.pm b/lib/CGI/Ex.pm index aae9e5d..e163008 100644 --- a/lib/CGI/Ex.pm +++ b/lib/CGI/Ex.pm @@ -24,7 +24,7 @@ use vars qw($VERSION use base qw(Exporter); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.06'; $PREFERRED_CGI_MODULE ||= 'CGI'; @EXPORT = (); @EXPORT_OK = qw(get_form diff --git a/lib/CGI/Ex/App.pm b/lib/CGI/Ex/App.pm index 4a62f92..34fdf11 100644 --- a/lib/CGI/Ex/App.pm +++ b/lib/CGI/Ex/App.pm @@ -10,9 +10,10 @@ use strict; use vars qw($VERSION); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.06'; Time::HiRes->import('time') if eval {require Time::HiRes}; + eval {require Scalar::Util}; } sub croak { @@ -767,7 +768,9 @@ sub swap_template { my ($self, $step, $file, $swap) = @_; my $args = $self->run_hook('template_args', $step); - $args->{'INCLUDE_PATH'} ||= sub { $self->base_dir_abs || die "Could not find base_dir_abs while looking for template INCLUDE_PATH on step \"$step\"" }; + my $copy = $self; + eval {require Scalar::Util; Scalar::Util::weaken($copy)}; + $args->{'INCLUDE_PATH'} ||= sub { $copy->base_dir_abs || die "Could not find base_dir_abs while looking for template INCLUDE_PATH on step \"$step\"" }; require CGI::Ex::Template; my $t = CGI::Ex::Template->new($args); @@ -951,14 +954,8 @@ sub hash_base { return $self->{'hash_base'} ||= do { ### create a weak copy of self to use in closures - my $copy; - if (eval {require Scalar::Util} && defined &Scalar::Util::weaken) { - $copy = $self; - Scalar::Util::weaken($copy); - } else { - $copy = bless {%$self}, ref($self); # hackish way to avoid circular refs on older perls (pre 5.8) - } - + my $copy = $self; + eval {require Scalar::Util; Scalar::Util::weaken($copy)}; my $hash = { script_name => $ENV{'SCRIPT_NAME'} || $0, path_info => $ENV{'PATH_INFO'} || '', diff --git a/lib/CGI/Ex/Auth.pm b/lib/CGI/Ex/Auth.pm index b8be486..33bdffe 100644 --- a/lib/CGI/Ex/Auth.pm +++ b/lib/CGI/Ex/Auth.pm @@ -18,7 +18,7 @@ use MIME::Base64 qw(encode_base64 decode_base64); use Digest::MD5 qw(md5_hex); use CGI::Ex; -$VERSION = '2.05'; +$VERSION = '2.06'; ###----------------------------------------------------------------### diff --git a/lib/CGI/Ex/Conf.pm b/lib/CGI/Ex/Conf.pm index 60b2d99..489c6b1 100644 --- a/lib/CGI/Ex/Conf.pm +++ b/lib/CGI/Ex/Conf.pm @@ -28,7 +28,7 @@ use vars qw($VERSION ); @EXPORT_OK = qw(conf_read conf_write in_cache); -$VERSION = '2.05'; +$VERSION = '2.06'; $DEFAULT_EXT = 'conf'; diff --git a/lib/CGI/Ex/Dump.pm b/lib/CGI/Ex/Dump.pm index af5a00b..0331603 100644 --- a/lib/CGI/Ex/Dump.pm +++ b/lib/CGI/Ex/Dump.pm @@ -17,7 +17,7 @@ use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION use strict; use Exporter; -$VERSION = '2.05'; +$VERSION = '2.06'; @ISA = qw(Exporter); @EXPORT = qw(dex dex_warn dex_text dex_html ctrace dex_trace); @EXPORT_OK = qw(dex dex_warn dex_text dex_html ctrace dex_trace debug); diff --git a/lib/CGI/Ex/Fill.pm b/lib/CGI/Ex/Fill.pm index 65cfa29..2ae971f 100644 --- a/lib/CGI/Ex/Fill.pm +++ b/lib/CGI/Ex/Fill.pm @@ -24,7 +24,7 @@ use vars qw($VERSION use base qw(Exporter); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.06'; @EXPORT = qw(form_fill); @EXPORT_OK = qw(fill form_fill html_escape get_tagval_by_key swap_tagval_by_key); }; diff --git a/lib/CGI/Ex/JSONDump.pm b/lib/CGI/Ex/JSONDump.pm index 69222bf..92d0837 100644 --- a/lib/CGI/Ex/JSONDump.pm +++ b/lib/CGI/Ex/JSONDump.pm @@ -17,7 +17,7 @@ use strict; use base qw(Exporter); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.06'; @EXPORT = qw(JSONDump); @EXPORT_OK = @EXPORT; @@ -117,7 +117,7 @@ sub js_escape { utf8::decode($str) if $self->{'utf8'} && &utf8::decode; ### escape and tags in the text - $str =~ s{() )}{$1$quote+$quote}gx; ### add nice newlines (unless pretty is off) if ($self->{'str_nl'} && length($str) > 80) { diff --git a/lib/CGI/Ex/Template.pm b/lib/CGI/Ex/Template.pm index 52d92a0..773000c 100644 --- a/lib/CGI/Ex/Template.pm +++ b/lib/CGI/Ex/Template.pm @@ -39,7 +39,7 @@ use vars qw($VERSION ); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.06'; $PACKAGE_EXCEPTION = 'CGI::Ex::Template::Exception'; $PACKAGE_ITERATOR = 'CGI::Ex::Template::Iterator'; @@ -280,6 +280,8 @@ BEGIN { $WHILE_MAX = 1000; $EXTRA_COMPILE_EXT = '.sto'; + + eval {require Scalar::Util}; }; ###----------------------------------------------------------------### @@ -1936,7 +1938,8 @@ sub play_MACRO { $sub_tree = $sub_tree->[0]->[4]; } - my $self_copy = $self->weak_copy; + my $self_copy = $self; + eval {require Scalar::Util; Scalar::Util::weaken($self_copy)}; ### install a closure in the stash that will handle the macro $self->set_variable($name, sub { @@ -2778,20 +2781,6 @@ sub list_plugins { }; } -### get a copy of self without circular refs for use in closures -sub weak_copy { - my $self = shift; - my $self_copy; - if (eval { require Scalar::Util } - && defined &Scalar::Util::weaken) { - $self_copy = $self; - Scalar::Util::weaken($self_copy); - } else { - $self_copy = bless {%$self}, ref($self); # hackish way to avoid circular refs on old perls (pre 5.8) - } - return $self_copy; -} - sub debug_node { my ($self, $node) = @_; my $info = $self->node_info($node); diff --git a/lib/CGI/Ex/Template.pod b/lib/CGI/Ex/Template.pod index 9d2c3c6..cbfde4b 100644 --- a/lib/CGI/Ex/Template.pod +++ b/lib/CGI/Ex/Template.pod @@ -2851,11 +2851,6 @@ by the pseudo context object and may disappear at some point. Methods by these names implement virtual methods that are more than one line. -=item C - -Used to create a weak reference to self to avoid circular references. (this -is needed by macros) - =back diff --git a/lib/CGI/Ex/Validate.pm b/lib/CGI/Ex/Validate.pm index 77ebd2a..55709d5 100644 --- a/lib/CGI/Ex/Validate.pm +++ b/lib/CGI/Ex/Validate.pm @@ -22,7 +22,7 @@ use vars qw($VERSION @UNSUPPORTED_BROWSERS ); -$VERSION = '2.05'; +$VERSION = '2.06'; $DEFAULT_EXT = 'val'; $QR_EXTRA = qr/^(\w+_error|as_(array|string|hash)_\w+|no_\w+)/; diff --git a/t/9_jsondump_00_base.t b/t/9_jsondump_00_base.t index a124a4f..29f6482 100644 --- a/t/9_jsondump_00_base.t +++ b/t/9_jsondump_00_base.t @@ -7,7 +7,7 @@ =cut use strict; -use Test::More tests => 49; +use Test::More tests => 52; use_ok('CGI::Ex::JSONDump'); @@ -89,6 +89,9 @@ test_dump('