From: Ryan Fox Date: Mon, 15 Mar 2010 11:06:55 +0000 (-0400) Subject: Adding a test for a bug where, if a class uses a role with an 'after' sub, and anothe... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fattic%2Frole_combination_bug;p=gitmo%2FMoose.git Adding a test for a bug where, if a class uses a role with an 'after' sub, and another role with the same parent is applied, the 'after' sub is no longer executed. --- diff --git a/t/100_bugs/029_apply_overwrites_previous_use_of_parent_role.t b/t/100_bugs/029_apply_overwrites_previous_use_of_parent_role.t new file mode 100644 index 0000000..1126498 --- /dev/null +++ b/t/100_bugs/029_apply_overwrites_previous_use_of_parent_role.t @@ -0,0 +1,56 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Test::More; + +{ + package parent_role; + use Moose::Role; + + # I just needed a value to write to, since the 'after' sub return value is ignored. + has 'value' => (is => 'rw', isa => 'Str'); + + sub foo { $_[0]->value('foo'); } +} + +{ + package child_role1; + use Moose::Role; + + with 'parent_role'; + + after 'foo' => sub { $_[0]->value('after foo'); } +} + +{ + package child_role2; + use Moose::Role; + + with 'parent_role'; +} + +{ + package my_class; + use Moose; + + with 'parent_role', 'child_role1'; + + 1; +} + +my $base_case = new my_class; +$base_case->foo(); +is($base_case->value, 'after foo', "after sub called for base case"); + +my $apply_child_role2 = new my_class; +Moose::Util::apply_all_roles($apply_child_role2, 'child_role2'); +$apply_child_role2->foo(); +is($apply_child_role2->value, 'after foo', "after sub called for base case + child_role2 added with apply_all_roles()"); + +my $ensure_child_role2 = new my_class; +Moose::Util::ensure_all_roles($ensure_child_role2, 'child_role2'); +$ensure_child_role2->foo(); +is($ensure_child_role2->value, 'after foo', "after sub called for base case + child_role2 added with ensure_all_roles()"); + +done_testing;