From: Stevan Little Date: Tue, 1 May 2007 21:46:40 +0000 (+0000) Subject: fixing this to work correctly X-Git-Tag: 0.18_01~89 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=88aaf2bdcbcc050eb6b0380dd0b10e4c9db6085a;p=gitmo%2FMooseX-AttributeHelpers.git fixing this to work correctly --- diff --git a/lib/MooseX/AttributeHelpers/Base.pm b/lib/MooseX/AttributeHelpers/Base.pm index 0c52869..1564d93 100644 --- a/lib/MooseX/AttributeHelpers/Base.pm +++ b/lib/MooseX/AttributeHelpers/Base.pm @@ -27,9 +27,9 @@ has '+type_constraint' => (required => 1); # this confirms that provides has # all valid possibilities in it sub _check_provides { - my ($self, $provides) = @_; + my $self = shift; my $method_constructors = $self->method_constructors; - foreach my $key (keys %$provides) { + foreach my $key (keys %{$self->provides}) { (exists $method_constructors->{$key}) || confess "$key is an unsupported method type"; } @@ -45,10 +45,9 @@ sub _process_options_for_provides { } before '_process_options' => sub { - my ($self, %options) = @_; - if (exists $options{provides}) { - $self->_check_provides($options{provides}); - $self->_process_options_for_provides(\%options); + my ($self, $name, $options) = @_; + if (exists $options->{provides}) { + $self->_process_options_for_provides($options); } }; @@ -56,6 +55,10 @@ after 'install_accessors' => sub { my $attr = shift; my $class = $attr->associated_class; + # before we install them, lets + # make sure they are valid + $attr->_check_provides; + my $method_constructors = $attr->method_constructors; foreach my $key (keys %{$attr->provides}) { diff --git a/lib/MooseX/AttributeHelpers/Collection/Array.pm b/lib/MooseX/AttributeHelpers/Collection/Array.pm index 043b035..77eabd8 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Array.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Array.pm @@ -1,6 +1,7 @@ package MooseX::AttributeHelpers::Collection::Array; use Moose; +use Moose::Util::TypeConstraints; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; @@ -57,11 +58,12 @@ sub _process_options_for_provides { (exists $options->{isa}) || confess "You must define a type with the Array metaclass"; - (find_type_constraint($options->{isa})->is_subtype_of('ArrayRef')) - || confess "The type constraint for a Array must be a subtype of ArrayRef"; + (find_type_constraint($options->{isa})->is_a_type_of('ArrayRef')) + || confess "The type constraint for a Array ($options->{isa}) must be a subtype of ArrayRef"; } no Moose; +no Moose::Util::TypeConstraints;; # register the alias ... package Moose::Meta::Attribute::Custom::Collection::Array; diff --git a/lib/MooseX/AttributeHelpers/Collection/Hash.pm b/lib/MooseX/AttributeHelpers/Collection/Hash.pm index c80cedc..684a1c5 100644 --- a/lib/MooseX/AttributeHelpers/Collection/Hash.pm +++ b/lib/MooseX/AttributeHelpers/Collection/Hash.pm @@ -1,6 +1,7 @@ package MooseX::AttributeHelpers::Collection::Hash; use Moose; +use Moose::Util::TypeConstraints; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; @@ -35,11 +36,12 @@ sub _process_options_for_provides { (exists $options->{isa}) || confess "You must define a type with the Hash metaclass"; - (find_type_constraint($options->{isa})->is_subtype_of('HashRef')) - || confess "The type constraint for a Hash must be a subtype of HashRef"; + (find_type_constraint($options->{isa})->is_a_type_of('HashRef')) + || confess "The type constraint for a Hash ($options->{isa}) must be a subtype of HashRef"; } no Moose; +no Moose::Util::TypeConstraints; # register the alias ... package Moose::Meta::Attribute::Custom::Collection::Hash; diff --git a/lib/MooseX/AttributeHelpers/Counter.pm b/lib/MooseX/AttributeHelpers/Counter.pm index 83ede3b..9339472 100644 --- a/lib/MooseX/AttributeHelpers/Counter.pm +++ b/lib/MooseX/AttributeHelpers/Counter.pm @@ -1,6 +1,7 @@ package MooseX::AttributeHelpers::Counter; use Moose; +use Moose::Util::TypeConstraints; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; @@ -27,11 +28,12 @@ sub _process_options_for_provides { (exists $options->{isa}) || confess "You must define a type with the Counter metaclass"; - (find_type_constraint($options->{isa})->is_subtype_of('Num')) - || confess "The type constraint for a Counter must be a subtype of Num"; + (find_type_constraint($options->{isa})->is_a_type_of('Num')) + || confess "The type constraint for a Counter ($options->{isa}) must be a subtype of Num"; } no Moose; +no Moose::Util::TypeConstraints; # register the alias ... package Moose::Meta::Attribute::Custom::Counter; diff --git a/t/100_collection_with_roles.t b/t/100_collection_with_roles.t index 8964854..7775c78 100644 --- a/t/100_collection_with_roles.t +++ b/t/100_collection_with_roles.t @@ -3,6 +3,8 @@ use strict; use warnings; +use Test::More no_plan => 1; + BEGIN { use_ok('MooseX::AttributeHelpers'); } diff --git a/t/pod_coverage.t b/t/pod_coverage.t index 7569358..9828e3d 100644 --- a/t/pod_coverage.t +++ b/t/pod_coverage.t @@ -6,6 +6,6 @@ use warnings; use Test::More; eval "use Test::Pod::Coverage 1.04"; -plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; +plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"; # if $@; all_pod_coverage_ok();