From: Yuval Kogman Date: Sat, 28 Jun 2008 12:38:13 +0000 (+0000) Subject: add UNIVERSAL::DOES support to Moose::Object X-Git-Tag: 0_55~75 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d0e9d54e136ac6c1bc94824277a62ec45ba16a2e;p=gitmo%2FMoose.git add UNIVERSAL::DOES support to Moose::Object --- diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 4eef559..e6ceebb 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -73,6 +73,14 @@ sub DESTROY { $_[0]->DEMOLISHALL; } +sub DOES { + my ( $self, $class_or_role_name ) = @_; + + $self->isa($class_or_role_name) + or + $self->does($class_or_role_name); +} + # new does() methods will be created # as approiate see Moose::Meta::Role sub does { @@ -156,6 +164,12 @@ This will call every C method in the inheritance hierarchy. This will check if the invocant's class C a given C<$role_name>. This is similar to C for object, but it checks the roles instead. +=item B + +A Moose Role aware implementation of L. + +C is equivalent to C or C. + =item B Cmon, how many times have you written the following code while debugging: diff --git a/t/000_recipes/010_roles.t b/t/000_recipes/010_roles.t index 5b8f9d2..fb6f834 100644 --- a/t/000_recipes/010_roles.t +++ b/t/000_recipes/010_roles.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 62; +use Test::More tests => 64; use Test::Exception; BEGIN { @@ -91,6 +91,9 @@ ok(US::Currency->does('Printable'), '... US::Currency does Printable'); my $hundred = US::Currency->new(amount => 100.00); isa_ok($hundred, 'US::Currency'); +ok( $hundred->DOES("US::Currency"), "UNIVERSAL::DOES for class" ); +ok( $hundred->DOES("Comparable"), "UNIVERSAL::DOES for role" ); + can_ok($hundred, 'amount'); is($hundred->amount, 100, '... got the right amount');