From: Graham Knop Date: Thu, 11 Jul 2013 08:30:58 +0000 (-0400) Subject: move role application backcompat hack before normal process X-Git-Tag: v1.003000~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2603ea93c8af870757f38ce7e7f2a944c29070f2;p=gitmo%2FRole-Tiny.git move role application backcompat hack before normal process If working with a subclass of Role::Tiny, run apply_single_role_to_package inside apply_roles_to_package as a backwards compatibility measure. Only do this as required for classes that haven't been adjusted to the new API. --- diff --git a/lib/Role/Tiny.pm b/lib/Role/Tiny.pm index f0f5d76..0ed7298 100644 --- a/lib/Role/Tiny.pm +++ b/lib/Role/Tiny.pm @@ -196,19 +196,26 @@ sub apply_roles_to_package { if ($INFO{$to}) { delete $INFO{$to}{methods}; # reset since we're about to add methods } - foreach my $step ($me->role_application_steps) { + + # backcompat: allow subclasses to use apply_single_role_to_package + # to apply changes. set a local var so ours does nothing. + our %BACKCOMPAT_HACK; + if($me ne __PACKAGE__ + and exists $BACKCOMPAT_HACK{$me} ? $BACKCOMPAT_HACK{$me} : + $BACKCOMPAT_HACK{$me} = + $me->can('role_application_steps') + == \&role_application_steps + && $me->can('apply_single_role_to_package') + != \&apply_single_role_to_package + ) { + local our $SKIP_APPLY = 1; foreach my $role (@roles) { - $me->$step($to, $role); + $me->apply_single_role_to_package($to, $role); } } - if ($me ne __PACKAGE__ - and $me->can('apply_single_role_to_package') - != \&apply_single_role_to_package) { - # backcompat: allow subclasses to use apply_single_role_to_package - # to apply changes. set a local var so ours does nothing. - local our $SKIP_APPLY = 1; + foreach my $step ($me->role_application_steps) { foreach my $role (@roles) { - $me->apply_single_role_to_package($to, $role); + $me->$step($to, $role); } } $APPLIED_TO{$to}{join('|',@roles)} = 1;