Permalink
Browse files

collection methods are now inherited by subclasses

  • Loading branch information...
alexrj committed Feb 6, 2011
1 parent 5d2e1fd commit c9b67f0953e4d0da3b7d09ccbbfddffa05122cb9
Showing with 36 additions and 2 deletions.
  1. +1 −0 Changes
  2. +3 −2 lib/MooseX/Collect.pm
  3. +32 −0 t/17-subclass.t
View
@@ -1,3 +1,4 @@
- collection methods are now inherited by subclasses
- fixed POD glitches
- added a CAVEATS section to the POD
View
@@ -84,10 +84,11 @@ sub parse_collect {
# generate the collection subroutine
my $body = sub {
my ($self, @args) = @_;
my $obj_meta = $self->meta;
# let's retrieve our superclasses
my (undef, @superclasses) = map $_->meta,
grep $_->can('meta'), $meta->linearized_isa;
grep $_->can('meta'), $obj_meta->linearized_isa;
@superclasses = ($superclasses[0]) if !$init_args{superclass_recurse};
# let's find out which methods we need to call
@@ -99,7 +100,7 @@ sub parse_collect {
my @metaclasses = ();
push @metaclasses, @superclasses if $_ eq 'superclasses';
push @metaclasses, grep !$_->isa('Moose::Meta::Role::Composite'),
$meta->calculate_all_roles_with_inheritance if $_ eq 'roles';
$obj_meta->calculate_all_roles_with_inheritance if $_ eq 'roles';
@metaclasses = reverse @metaclasses if $init_args{method_order} eq 'reverse';
push @methods,
map $_->get_method($init_args{provider}),
View
@@ -0,0 +1,32 @@
use strict;
use warnings;
use Test::More tests => 1;
{
package Foo;
use Moose;
use MooseX::Collect;
use t::classes;
sub items { qw/me/ }
collect 'items' => (
from => 'roles',
);
extends 'E';
}
{
package Bar;
use Moose;
extends 'Foo';
with qw(B C);
}
is_deeply(
[ Bar->new->items ],
[qw(b a a2 c)],
'subclassed collector'
);

0 comments on commit c9b67f0

Please sign in to comment.