From: Nick Woolley <nick@noodlefactory.co.uk> Date: Fri, 27 Mar 2009 14:42:22 +0000 (+0000) Subject: Implemented Moose::Object::does, borrowing from Moose::Object. X-Git-Tag: 0.20~60 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=56a558f97f2da37b37db51a6a8ef7f923e84724e;p=gitmo%2FMouse.git Implemented Moose::Object::does, borrowing from Moose::Object. --- diff --git a/lib/Mouse/Object.pm b/lib/Mouse/Object.pm index d729261..079aa80 100644 --- a/lib/Mouse/Object.pm +++ b/lib/Mouse/Object.pm @@ -120,6 +120,20 @@ sub dump { Data::Dumper::Dumper $self; } + +sub does { + my ($self, $role_name) = @_; + (defined $role_name) + || confess "You must supply a role name to does()"; + my $meta = $self->meta; + foreach my $class ($meta->linearized_isa) { + my $m = $meta->initialize($class); + return 1 + if $m->can('does_role') && $m->does_role($role_name); + } + return 0; +}; + 1; __END__ @@ -160,6 +174,12 @@ You may put any business logic deinitialization in DEMOLISH methods. You don't need to redispatch or return any specific value. +=head2 does $role_name + +This will check if the invocant's class "does" a given C<$role_name>. +This is similar to "isa" for object, but it checks the roles instead. + + =head2 B<dump ($maxdepth)> From the Moose POD: