[Rt-commit] r5637 - Object-Declare/lib/Object

audreyt at bestpractical.com audreyt at bestpractical.com
Fri Jul 21 00:41:33 EDT 2006


Author: audreyt
Date: Fri Jul 21 00:41:33 2006
New Revision: 5637

Modified:
   Object-Declare/lib/Object/Declare.pm

Log:
* factor our predeclaration

Modified: Object-Declare/lib/Object/Declare.pm
==============================================================================
--- Object-Declare/lib/Object/Declare.pm	(original)
+++ Object-Declare/lib/Object/Declare.pm	Fri Jul 21 00:41:33 2006
@@ -15,7 +15,7 @@
 
     my $mapping     = $args{mapping} or return;
     my $declarator  = $args{declarator} || ['declare'];
-    my $copula      = $args{copula}     || ['is', 'are', 'isn::t'];
+    my $copula      = $args{copula}     || ['is', 'are'];
 
     # Both declarator and copula can contain more than one entries;
     # normalize into an arrayref if we only have on entry.
@@ -62,9 +62,19 @@
     # Establish prototypes (same as "use subs") so Sub::Override can work
     {
         no strict 'refs';
-        *{"$from\::$_"}     = \&{"$from\::$_"} for keys %$mapping;
-        *{"UNIVERSAL::$_"}  = \&{"UNIVERSAL::$_"} for keys %$copula;
-        *{"$_\::AUTOLOAD"}  = \&{"$_\::AUTOLOAD"} for keys %$copula;
+        _predeclare(
+            (map { "$from\::$_" } keys %$mapping),
+            (map { ("UNIVERSAL::$_", "$_\::AUTOLOAD") } keys %$copula),
+        );
+    }
+}
+
+# Same as "use sub".  All is fair if you predeclare.
+sub _predeclare {
+    no strict 'refs';
+    no warnings 'redefine';
+    foreach my $sym (@_) {
+        *$sym = \&$sym;
     }
 }
 
@@ -87,7 +97,7 @@
         # Sub::Override cannot handle empty symbol slots.  This is normally
         # redundant (&import already did that), but we do it here anyway to
         # guard against runtime deletion of symbol table entries.
-        *$sym = \&$sym;
+        _predeclare($sym);
 
         # Now replace the symbol for real.
         $override->replace($sym => $code);


More information about the Rt-commit mailing list