Skip to content

Instantly share code, notes, and snippets.

@wchristian
Created November 3, 2022 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchristian/fcd1d222ea7ccac1a10141b128108a70 to your computer and use it in GitHub Desktop.
Save wchristian/fcd1d222ea7ccac1a10141b128108a70 to your computer and use it in GitHub Desktop.
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