Created
April 2, 2020 02:44
-
-
Save jjn1056/5543c977a2829f624947b93fd2628892 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MooX::TrackRoles; | |
use Role::Tiny (); | |
sub import { | |
my $class = shift; | |
my $target = caller; | |
die "'$target' is not a Role" unless Role::Tiny->is_role($target); | |
eval qq[ | |
package ${target}; | |
sub does_roles { shift->maybe::next::method(\@_) } | |
]; | |
my $around = \&{"${target}::around"}; | |
$around->(does_roles => sub { | |
my ($orig, $self) = @_; | |
return ($self->$orig, $target); | |
}); | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment