From: Stevan Little Date: Fri, 14 Mar 2008 14:54:19 +0000 (+0000) Subject: some changes X-Git-Tag: 0_55~280 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=587e457d858eb5130ec7b5a3fc5cda2e6170e643;p=gitmo%2FMoose.git some changes --- diff --git a/Changes b/Changes index 49ef020..dde9c70 100644 --- a/Changes +++ b/Changes @@ -49,6 +49,9 @@ Revision history for Perl extension Moose have slightly better support for AUTOLOADed objects - added more delegation tests + - adding ->does method to this so as to better + support traits and their introspection. + - added tests for this * Moose::Object - localizing the Data::Dumper configurations so diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 80c16cd..c45cae9 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -47,6 +47,14 @@ __PACKAGE__->meta->add_attribute('documentation' => ( predicate => 'has_documentation', )); +# NOTE: +# we need to have a ->does method in here to +# more easily support traits, and the introspection +# of those traits. So in order to do this we +# just alias Moose::Object's version of it. +# - SL +*does = \&Moose::Object::does; + sub new { my ($class, $name, %options) = @_; $class->_process_options($name, \%options); diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index b5fb037..90ca089 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -62,8 +62,9 @@ sub does { || confess "You much supply a role name to does()"; my $meta = $self->meta; foreach my $class ($meta->class_precedence_list) { + my $m = $meta->initialize($class); return 1 - if $meta->initialize($class)->does_role($role_name); + if $m->can('does_role') && $m->does_role($role_name); } return 0; } diff --git a/t/020_attributes/015_attribute_traits.t b/t/020_attributes/015_attribute_traits.t index 8c985fa..7eb265b 100644 --- a/t/020_attributes/015_attribute_traits.t +++ b/t/020_attributes/015_attribute_traits.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 8; use Test::Exception; use Test::Moose; @@ -36,18 +36,26 @@ BEGIN { isa => 'Int', alias_to => 'baz', ); + + has 'gorch' => ( + is => 'ro', + isa => 'Int', + default => sub { 10 } + ); } my $c = My::Class->new(bar => 100); isa_ok($c, 'My::Class'); is($c->bar, 100, '... got the right value for bar'); +is($c->gorch, 10, '... got the right value for gorch'); can_ok($c, 'baz'); is($c->baz, 100, '... got the right value for baz'); does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait'); +ok(!$c->meta->get_attribute('gorch')->does('My::Attribute::Trait'), '... gorch doesnt do the trait');