X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=lib%2FCGI%2FEx%2FApp.pm;h=739c82fb755307e22a63d39f28257b1fd723639c;hb=d0287461de3f9b5c49ce02b22957022bdc5e87d8;hp=0c3b1f7277cb9c7f511fc7cf27d92cd8a504976e;hpb=d2b7c937e86e6e8c4b4193e9f4a8da075919b4fd;p=chaz%2Fp5-CGI-Ex diff --git a/lib/CGI/Ex/App.pm b/lib/CGI/Ex/App.pm index 0c3b1f7..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.03'; + $VERSION = '2.07'; Time::HiRes->import('time') if eval {require Time::HiRes}; + eval {require Scalar::Util}; } sub croak { @@ -382,6 +383,8 @@ sub run_hook { my ($code, $found) = @{ $self->find_hook($hook, $step) }; if (! $code) { croak "Could not find a method named ${step}_${hook} or ${hook}"; + } elsif (! UNIVERSAL::isa($code, 'CODE')) { + croak "Value for $hook ($found) is not a code ref ($code)"; } ### record history @@ -671,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 @@ -765,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); @@ -949,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'} || '',