From: Stevan Little Date: Wed, 11 Jul 2007 21:04:36 +0000 (+0000) Subject: foo X-Git-Tag: 0.18_01~71 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9810162d2223e3165f6e9332898731c301d47742;p=gitmo%2FMooseX-AttributeHelpers.git foo --- diff --git a/lib/MooseX/AttributeHelpers/Base.pm b/lib/MooseX/AttributeHelpers/Base.pm index e195198..93f72fb 100644 --- a/lib/MooseX/AttributeHelpers/Base.pm +++ b/lib/MooseX/AttributeHelpers/Base.pm @@ -10,9 +10,9 @@ extends 'Moose::Meta::Attribute'; # this is the method map you define ... has 'provides' => ( - is => 'ro', - isa => 'HashRef', - required => 1, + is => 'ro', + isa => 'HashRef', + default => sub {{}} ); @@ -76,7 +76,8 @@ sub process_options_for_provides { before '_process_options' => sub { my ($self, $name, $options) = @_; - if (exists $options->{provides}) { + if (exists $options->{provides} || + exists $options->{isa} && $options->{isa} =~ /^.*?\[.*?\]$/) { $self->process_options_for_provides($options); } }; diff --git a/lib/MooseX/AttributeHelpers/Collection.pm b/lib/MooseX/AttributeHelpers/Collection.pm index 12c3d99..e277a01 100644 --- a/lib/MooseX/AttributeHelpers/Collection.pm +++ b/lib/MooseX/AttributeHelpers/Collection.pm @@ -15,13 +15,12 @@ has 'container_type' => ( ); has 'container_type_constraint' => ( - is => 'rw', - isa => 'Moose::Meta::TypeConstraint', - required => 1, + is => 'rw', + isa => 'Moose::Meta::TypeConstraint', ); before 'process_options_for_provides' => sub { - my ($self, $options) = @_; + my ($self, $options) = @_; if (exists $options->{isa}) { my $type = $options->{isa}; diff --git a/t/010_array_from_role.t b/t/010_array_from_role.t new file mode 100644 index 0000000..c28a0f7 --- /dev/null +++ b/t/010_array_from_role.t @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More no_plan => 1; +use Test::Exception; + +BEGIN { + use_ok('MooseX::AttributeHelpers'); +} + +{ + package Foo; + use Moose; + + has 'bar' => (is => 'rw'); + + package Stuffed::Role; + use Moose::Role; + + has 'options' => ( + metaclass => 'Collection::Array', + is => 'ro', + isa => 'ArrayRef[Foo]', + ); + + package Bulkie::Role; + use Moose::Role; + + has 'stuff' => ( + metaclass => 'Collection::Array', + is => 'ro', + isa => 'ArrayRef', + provides => { + 'get' => 'get_stuff' + } + ); + + package Stuff; + use Moose; + + ::lives_ok { + with 'Stuffed::Role'; + } '... this should work correctly'; + + ::lives_ok { + with 'Bulkie::Role'; + } '... this should work correctly'; + +}