$NetBSD: patch-aa,v 1.5 2009/08/26 17:39:01 sno Exp $

# Fixes RT #48989

--- lib/Template/Plugin/Procedural.pm.orig	2009-08-25 11:19:17.219629000 +0200
+++ lib/Template/Plugin/Procedural.pm	2009-08-25 11:21:08.970766000 +0200
@@ -39,34 +39,40 @@
     # 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!^.*::!!;
-
-        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);
-
-        # 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;
-
-        return "";
-    };
+    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;
+
+            # 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->(@_);
+            }
+
+            print STDERR "Eeek, no such method '$AUTOLOAD'\n"
+                if $DEBUG;
+
+            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;
 }
