From: Jason May Date: Sun, 22 Jun 2008 20:28:12 +0000 (+0000) Subject: up the version, add some checks for the curries feature X-Git-Tag: 0.16~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=96c2370b439dea594023a0808b750716c5c75d12;p=gitmo%2FMooseX-AttributeHelpers.git up the version, add some checks for the curries feature --- diff --git a/ChangeLog b/ChangeLog index 3f07ffb..1f8654b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Revision history for Perl extension MooseX-AttributeHelpers +0.11 + - add the ability to curry method providers (thanks to jasonmay) + 0.10 - Counter: add set and allow inc and dec to accept args - add Bool as an attribute helper (thanks to jasonmay) diff --git a/README b/README index eaebf00..f97fbca 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -MooseX::AttributeHelpers version 0.09 +MooseX::AttributeHelpers version 0.11 =========================== See the individual module documentation for more information diff --git a/lib/MooseX/AttributeHelpers.pm b/lib/MooseX/AttributeHelpers.pm index 4dad2af..47f9814 100644 --- a/lib/MooseX/AttributeHelpers.pm +++ b/lib/MooseX/AttributeHelpers.pm @@ -1,7 +1,7 @@ package MooseX::AttributeHelpers; -our $VERSION = '0.09'; +our $VERSION = '0.11'; our $AUTHORITY = 'cpan:STEVAN'; use MooseX::AttributeHelpers::Meta::Method::Provided; diff --git a/lib/MooseX/AttributeHelpers/Base.pm b/lib/MooseX/AttributeHelpers/Base.pm index b274ee2..201bbcb 100644 --- a/lib/MooseX/AttributeHelpers/Base.pm +++ b/lib/MooseX/AttributeHelpers/Base.pm @@ -87,7 +87,7 @@ before '_process_options' => sub { ## methods called after instantiation -# this confirms that provides has +# this confirms that provides (and curries) has # all valid possibilities in it sub check_provides_values { my $self = shift; @@ -98,6 +98,11 @@ sub check_provides_values { (exists $method_constructors->{$key}) || confess "$key is an unsupported method type"; } + + foreach my $key (keys %{$self->curries}) { + (exists $method_constructors->{$key}) + || confess "$key is an unsupported method type"; + } } sub _curry { @@ -105,7 +110,10 @@ sub _curry { my $code = shift; my @args = @_; - return sub { my $self = shift; $code->($self, @args, @_) }; + return sub { + my $self = shift; + $code->($self, @args, @_) + }; } sub _curry_sub { @@ -113,9 +121,10 @@ sub _curry_sub { my $body = shift; my $code = shift; - warn "installing sub!"; - - return sub { my $self = shift; $code->($self, $body, @_) }; + return sub { + my $self = shift; + $code->($self, $body, @_) + }; } after 'install_accessors' => sub { @@ -132,7 +141,6 @@ after 'install_accessors' => sub { # before we install them, lets # make sure they are valid $attr->check_provides_values; -# $attr->check_curries_values; my $method_constructors = $attr->method_constructors; @@ -199,6 +207,8 @@ after 'install_accessors' => sub { after 'remove_accessors' => sub { my $attr = shift; my $class = $attr->associated_class; + + # provides accessors foreach my $key (keys %{$attr->provides}) { my $method_name = $attr->provides->{$key}; my $method = $class->get_method($method_name); @@ -206,6 +216,15 @@ after 'remove_accessors' => sub { if blessed($method) && $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided'); } + + # curries accessors + foreach my $key (keys %{$attr->curries}) { + my $method_name = $attr->curries->{$key}; + my $method = $class->get_method($method_name); + $class->remove_method($method_name) + if blessed($method) && + $method->isa('MooseX::AttributeHelpers::Meta::Method::Provided'); + } }; no Moose;