Revision 1260
- Date:
- 2010/06/08 16:51:05
- Files:
Legend:
- Added
- Removed
- Modified
-
trunk/Changes
18 18 in a template. It's not documented yet. See t/trace_vars.t for an 19 19 example of use. 20 20 21 * Applied patch from RT#48989 to avoid Template::Plugin::Procedural 22 from adding target class' methods AUTOLOAD and new methods multiple 23 times (Jens Rehsack) 21 24 22 25 #----------------------------------------------------------------------- 23 26 # Version 2.22 - 21st July 2009 -
trunk/lib/Template/Plugin/Procedural.pm
39 39 # okay, in our proxy create the autoload routine that will 40 40 # call the right method in the real class 41 41 no strict "refs"; 42 *{ $proxy . "::AUTOLOAD" } = sub { 43 # work out what the method is called 44 $AUTOLOAD =~ s!^.*::!!; 42 unless( defined( *{ $proxy . "::AUTOLOAD" } ) ) { 43 *{ $proxy . "::AUTOLOAD" } = sub { 44 # work out what the method is called 45 $AUTOLOAD =~ s!^.*::!!; 45 46 46 print STDERR "Calling '$AUTOLOAD' in '$class'\n" 47 if $DEBUG; 47 print STDERR "Calling '$AUTOLOAD' in '$class'\n" 48 if $DEBUG; 48 49 49 # look up the sub for that method (but in a OO way) 50 my $uboat = $class->can($AUTOLOAD); 50 # look up the sub for that method (but in a OO way) 51 my $uboat = $class->can($AUTOLOAD); 51 52 52 # if it existed call it as a subroutine, not as a method 53 if ($uboat) { 54 shift @_; 55 return $uboat->(@_); 56 } 53 # if it existed call it as a subroutine, not as a method 54 if ($uboat) { 55 shift @_; 56 return $uboat->(@_); 57 } 57 58 58 print STDERR "Eeek, no such method '$AUTOLOAD'\n" 59 if $DEBUG; 59 print STDERR "Eeek, no such method '$AUTOLOAD'\n" 60 if $DEBUG; 60 61 61 return ""; 62 }; 62 return ""; 63 }; 64 } 63 65 64 66 # create a simple new method that simply returns a blessed 65 67 # scalar as the object. 66 *{ $proxy . "::new" } = sub { 67 my $this; 68 return bless \$this, $_[0]; 69 }; 68 unless( defined( *{ $proxy . "::new" } ) ) { 69 *{ $proxy . "::new" } = sub { 70 my $this; 71 return bless \$this, $_[0]; 72 }; 73 } 70 74 71 75 return $proxy; 72 76 }