Created
November 3, 2022 12:52
-
-
Save wchristian/fcd1d222ea7ccac1a10141b128108a70 to your computer and use it in GitHub Desktop.
This file contains 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 Moose::Meta::Protect; | |
use strictures 2; | |
use Package::Stash; | |
use Module::Runtime 'use_module'; | |
use Exporter 'import'; | |
our @EXPORT_OK = qw( protect_modifiers ); | |
1; | |
sub protect_modifiers { | |
my $stash = Package::Stash->new( (caller)[0] ); | |
for my $role (@_) { | |
my $meta = use_module($role)->meta; | |
my @list = map $meta->get_method_modifier_list($_), qw( around before after ); | |
for my $meth (@list) { | |
next unless # | |
my $old_symbol = $stash->get_symbol("&$meth"); | |
$stash->add_symbol( "&_orig_$meth", $old_symbol ); | |
} | |
} | |
return @_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment