X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FApp.pm;h=739c82fb755307e22a63d39f28257b1fd723639c;hb=d0287461de3f9b5c49ce02b22957022bdc5e87d8;hp=4a62f920b390b9228abc345090b23c1429e0415b;hpb=48c4840be1f154e262de2c161cb86dc5000dfe47;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/App.pm b/lib/CGI/Ex/App.pm index 4a62f92..739c82f 100644 --- a/lib/CGI/Ex/App.pm +++ b/lib/CGI/Ex/App.pm @@ -2,7 +2,7 @@ package CGI::Ex::App; ###----------------------------------------------------------------### # See the perldoc in CGI/Ex/App.pod -# Copyright 2006 - Paul Seamons # +# Copyright 2007 - Paul Seamons # # Distributed under the Perl Artistic License without warranty # ###----------------------------------------------------------------### @@ -10,9 +10,10 @@ use strict; use vars qw($VERSION); BEGIN { - $VERSION = '2.05'; + $VERSION = '2.07'; Time::HiRes->import('time') if eval {require Time::HiRes}; + eval {require Scalar::Util}; } sub croak { @@ -673,6 +674,29 @@ sub stash { return $self->{'stash'} ||= {}; } +sub clear_app { + my $self = shift; + + delete @{ $self }{qw( + cgix + vob + form + cookies + stash + path + path_i + history + __morph_lineage_start_index + __morph_lineage + hash_errors + hash_fill + hash_swap + hash_common + )}; + + return $self; +} + ###----------------------------------------------------------------### ### default hook implementations @@ -767,7 +791,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 +977,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'} || '',