adding method meta-object so that you can differentiate between provided methods...
Stevan Little [Sun, 27 May 2007 18:03:37 +0000 (18:03 +0000)]
lib/MooseX/AttributeHelpers.pm
lib/MooseX/AttributeHelpers/Base.pm
lib/MooseX/AttributeHelpers/Meta/Method/Provided.pm [new file with mode: 0644]

index f713e3a..138ceb8 100644 (file)
@@ -4,6 +4,8 @@ package MooseX::AttributeHelpers;
 our $VERSION   = '0.01';
 our $AUTHORITY = 'cpan:STEVAN';
 
+use MooseX::AttributeHelpers::Meta::Method::Provided;
+
 use MooseX::AttributeHelpers::Counter;
 use MooseX::AttributeHelpers::Number;
 use MooseX::AttributeHelpers::Collection::Array;
index 9e6113b..533c083 100644 (file)
@@ -78,9 +78,18 @@ after 'install_accessors' => sub {
     my $method_constructors = $attr->method_constructors;
     
     foreach my $key (keys %{$attr->provides}) {
-        $class->add_method(
-            $attr->provides->{$key}, 
-            $method_constructors->{$key}->($attr)
+        
+        my $method_name = $attr->provides->{$key};
+        my $method_body = $method_constructors->{$key}->($attr);
+        
+        if ($class->has_method($method_name)) {
+            confess "The method ($method_name) already exists in class (" . $class->name . ")";
+        }
+        
+        $class->add_method($method_name => 
+            MooseX::AttributeHelpers::Meta::Method::Provided->wrap(
+                $method_body,
+            )
         );
     }
 };
diff --git a/lib/MooseX/AttributeHelpers/Meta/Method/Provided.pm b/lib/MooseX/AttributeHelpers/Meta/Method/Provided.pm
new file mode 100644 (file)
index 0000000..78fa817
--- /dev/null
@@ -0,0 +1,13 @@
+
+package MooseX::AttributeHelpers::Meta::Method::Provided;
+use Moose;
+
+extends 'Moose::Meta::Method';
+
+1;
+
+__END__
+
+=pod
+
+=cut
\ No newline at end of file