[Rt-commit] r5593 - in Object-Declare: lib/Object

audreyt at bestpractical.com audreyt at bestpractical.com
Mon Jul 17 19:46:07 EDT 2006


Author: audreyt
Date: Mon Jul 17 19:46:06 2006
New Revision: 5593

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

Log:
* This be 0.03.
* The declarator can now be exported to another package;
  this works because internally, each declarator remembers
  the class mappings and copula it was associated with.

Modified: Object-Declare/Changes
==============================================================================
--- Object-Declare/Changes	(original)
+++ Object-Declare/Changes	Mon Jul 17 19:46:06 2006
@@ -1,3 +1,9 @@
+[Changes for 0.03 - 2006-07-17]
+
+* The declarator can now be exported to another package;
+  this works because internally, each declarator remembers
+  the class mappings and copula it was associated with.
+
 [Changes for 0.02 - 2006-07-17]
 
 * Documentation cleanup; no functional changes.

Modified: Object-Declare/lib/Object/Declare.pm
==============================================================================
--- Object-Declare/lib/Object/Declare.pm	(original)
+++ Object-Declare/lib/Object/Declare.pm	Mon Jul 17 19:46:06 2006
@@ -1,5 +1,5 @@
 package Object::Declare;
-$Object::Declare::VERSION = '0.02';
+$Object::Declare::VERSION = '0.03';
 
 use 5.006;
 use strict;
@@ -7,9 +7,6 @@
 use Carp;
 use Sub::Override;
 
-my %ClassMapping;
-my %ClassCopula;
-
 sub import {
     my $class       = shift;
     my %args        = ((@_ and ref($_[0])) ? (mapping => $_[0]) : @_) or return; 
@@ -37,21 +34,21 @@
 
     {
         no strict 'refs';
-        *{"$from\::$_"} = \&declare for @$declarator;
+        *{"$from\::$_"} = sub (&) {
+            unshift @_, ($mapping, $copula);
+            goto &_declare;
+        } for @$declarator;
         *{"$from\::$_"} = \&{"$from\::$_"} for keys %$mapping;
         *{"UNIVERSAL::$_"} = \&{"UNIVERSAL::$_"} for @$copula;
         *{"$_\::AUTOLOAD"} = \&{"$_\::AUTOLOAD"} for @$copula;
     }
-
-    $ClassMapping{$from} = $mapping;
-    $ClassCopula{$from}  = $copula;
 }
 
-sub declare (&) {
-    my $code = shift;
-    my $from = caller;
-    my $mapping = $ClassMapping{$from} or carp "No mapping defined in $from\n";
-    my $copula  = $ClassCopula{$from} or carp "No copula defined in $from\n";
+sub _declare (&) {
+    my $mapping = shift;
+    my $copula  = shift;
+    my $code    = shift;
+    my $from    = caller;
 
     # Table of collected objects.
     my $objects = {};


More information about the Rt-commit mailing list