From: Stevan Little Date: Sun, 27 May 2007 18:03:37 +0000 (+0000) Subject: adding method meta-object so that you can differentiate between provided methods... X-Git-Tag: 0.18_01~77 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f7951c9a2ef1fb01d8e04e277df1099102fedf8;p=gitmo%2FMooseX-AttributeHelpers.git adding method meta-object so that you can differentiate between provided methods and non-provided --- diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index f713e3a..138ceb8 100644 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@ -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; diff --git a/lib/MooseX/AttributeHelpers/Base.pm b/lib/MooseX/AttributeHelpers/Base.pm index 9e6113b..533c083 100644 --- a/lib/MooseX/AttributeHelpers/Base.pm +++ b/lib/MooseX/AttributeHelpers/Base.pm @@ -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 index 0000000..78fa817 --- /dev/null +++ b/lib/MooseX/AttributeHelpers/Meta/Method/Provided.pm @@ -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