Revision history for Perl extension Moose
+0.62
+ * Moose::Meta::Role::Application::ToClass
+ Moose::Meta::Role::Application::ToRole
+ - fixed issues where excluding and aliasing the
+ same methods for a single role did not work
+ right (worked just fine with multiple roles)
+ - added test for this
+
0.61 Fri November 7, 2008
* Moose::Meta::Attribute
- When passing a role to handles, it will be loaded if necessary
t/030_roles/030_role_parameterized.t
t/030_roles/031_roles_applied_in_create.t
t/030_roles/032_roles_and_method_cloning.t
+t/030_roles/033_role_exclusion_and_alias_bug.t
t/040_type_constraints/001_util_type_constraints.t
t/040_type_constraints/002_util_type_constraints_export.t
t/040_type_constraints/003_util_std_type_constraints.t
my ($self, $role, $class) = @_;
foreach my $method_name ($role->get_method_list) {
- next if $self->is_method_excluded($method_name);
-
- # it if it has one already
- if ($class->has_method($method_name) &&
- # and if they are not the same thing ...
- $class->get_method($method_name)->body != $role->get_method($method_name)->body) {
- next;
- }
- else {
- # add it, although it could be overriden
- $class->add_method(
- $method_name,
- $role->get_method($method_name)
- );
+ unless ($self->is_method_excluded($method_name)) {
+ # it if it has one already
+ if ($class->has_method($method_name) &&
+ # and if they are not the same thing ...
+ $class->get_method($method_name)->body != $role->get_method($method_name)->body) {
+ next;
+ }
+ else {
+ # add it, although it could be overriden
+ $class->add_method(
+ $method_name,
+ $role->get_method($method_name)
+ );
+ }
}
if ($self->is_method_aliased($method_name)) {
sub apply_methods {
my ($self, $role1, $role2) = @_;
foreach my $method_name ($role1->get_method_list) {
-
- next if $self->is_method_excluded($method_name);
if ($self->is_method_aliased($method_name)) {
my $aliased_method_name = $self->get_method_aliases->{$method_name};
);
if (!$role2->has_method($method_name)) {
- $role2->add_required_methods($method_name);
+ $role2->add_required_methods($method_name)
+ unless $self->is_method_excluded($method_name);
}
next;
- }
+ }
+
+ next if $self->is_method_excluded($method_name);
# it if it has one already
if ($role2->has_method($method_name) &&
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 17;
+use Test::Moose;
+
+{
+ package My::Role;
+ use Moose::Role;
+
+ sub foo { "FOO" }
+ sub bar { "BAR" }
+}
+
+{
+ package My::Class;
+ use Moose;
+
+ with 'My::Role' => {
+ alias => { foo => 'baz', bar => 'gorch' },
+ excludes => ['foo', 'bar'],
+ };
+}
+
+{
+ my $x = My::Class->new;
+ isa_ok($x, 'My::Class');
+ does_ok($x, 'My::Role');
+
+ can_ok($x, $_) for qw[baz gorch];
+
+ ok(!$x->can($_), '... cant call method ' . $_) for qw[foo bar];
+
+ is($x->baz, 'FOO', '... got the right value');
+ is($x->gorch, 'BAR', '... got the right value');
+}
+
+{
+ package My::Role::Again;
+ use Moose::Role;
+
+ with 'My::Role' => {
+ alias => { foo => 'baz', bar => 'gorch' },
+ excludes => ['foo', 'bar'],
+ };
+
+ package My::Class::Again;
+ use Moose;
+
+ with 'My::Role::Again';
+}
+
+{
+ my $x = My::Class::Again->new;
+ isa_ok($x, 'My::Class::Again');
+ does_ok($x, 'My::Role::Again');
+ does_ok($x, 'My::Role');
+
+ can_ok($x, $_) for qw[baz gorch];
+
+ ok(!$x->can($_), '... cant call method ' . $_) for qw[foo bar];
+
+ is($x->baz, 'FOO', '... got the right value');
+ is($x->gorch, 'BAR', '... got the right value');
+}
+
+