Skip to content
Browse files

* Applied patch from RT#48989 to avoid Template::Plugin::Procedural

  from adding target class' methods AUTOLOAD and new methods multiple
  times (Jens Rehsack)


git-svn-id: svn://svn.tt2.org/tt/Template2/trunk@1260 d5a88997-0a34-4036-9ed2-92fb5d660d91
  • Loading branch information...
1 parent 702254f commit 731b1994fd9689488767d09c6658930f30ea98ef @rehsack rehsack committed Jun 8, 2010
Showing with 27 additions and 20 deletions.
  1. +3 −0 Changes
  2. +24 −20 lib/Template/Plugin/Procedural.pm
View
3 Changes
@@ -18,6 +18,9 @@
in a template. It's not documented yet. See t/trace_vars.t for an
example of use.
+* Applied patch from RT#48989 to avoid Template::Plugin::Procedural
+ from adding target class' methods AUTOLOAD and new methods multiple
+ times (Jens Rehsack)
#-----------------------------------------------------------------------
# Version 2.22 - 21st July 2009
View
44 lib/Template/Plugin/Procedural.pm
@@ -39,34 +39,38 @@ sub load {
# okay, in our proxy create the autoload routine that will
# call the right method in the real class
no strict "refs";
- *{ $proxy . "::AUTOLOAD" } = sub {
- # work out what the method is called
- $AUTOLOAD =~ s!^.*::!!;
+ unless( defined( *{ $proxy . "::AUTOLOAD" } ) ) {
+ *{ $proxy . "::AUTOLOAD" } = sub {
+ # work out what the method is called
+ $AUTOLOAD =~ s!^.*::!!;
- print STDERR "Calling '$AUTOLOAD' in '$class'\n"
- if $DEBUG;
+ print STDERR "Calling '$AUTOLOAD' in '$class'\n"
+ if $DEBUG;
- # look up the sub for that method (but in a OO way)
- my $uboat = $class->can($AUTOLOAD);
+ # look up the sub for that method (but in a OO way)
+ my $uboat = $class->can($AUTOLOAD);
- # if it existed call it as a subroutine, not as a method
- if ($uboat) {
- shift @_;
- return $uboat->(@_);
- }
+ # if it existed call it as a subroutine, not as a method
+ if ($uboat) {
+ shift @_;
+ return $uboat->(@_);
+ }
- print STDERR "Eeek, no such method '$AUTOLOAD'\n"
- if $DEBUG;
+ print STDERR "Eeek, no such method '$AUTOLOAD'\n"
+ if $DEBUG;
- return "";
- };
+ return "";
+ };
+ }
# create a simple new method that simply returns a blessed
# scalar as the object.
- *{ $proxy . "::new" } = sub {
- my $this;
- return bless \$this, $_[0];
- };
+ unless( defined( *{ $proxy . "::new" } ) ) {
+ *{ $proxy . "::new" } = sub {
+ my $this;
+ return bless \$this, $_[0];
+ };
+ }
return $proxy;
}

0 comments on commit 731b199

Please sign in to comment.
Something went wrong with that request. Please try again.