3 no warnings 'once'; # guard against -w
5 sub _getglob { \*{$_[0]} }
6 sub _getstash { \%{"$_[0]::"} }
8 use constant lt_5_8_3 => ( $] < 5.008003 ) ? 1 : 0;
9 use constant can_haz_subname => eval { require Sub::Name };
12 use Module::Runtime qw(require_module);
13 use Devel::GlobalDestruction;
14 use base qw(Exporter);
18 _getglob _install_modifier _load_module _maybe_load_module
19 _get_linear_isa _getstash _install_coderef _name_coderef
22 sub _install_modifier {
23 my ($into, $type, $name, $code) = @_;
25 if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
27 Sub::Defer::undefer_sub($to_modify);
30 Class::Method::Modifiers::install_modifier(@_);
36 (my $proto = $_[0]) =~ s/::/\//g;
37 return 1 if $INC{"${proto}.pm"};
38 # can't just ->can('can') because a sub-package Foo::Bar::Baz
39 # creates a 'Baz::' key in Foo::Bar's symbol table
40 my $stash = _getstash($_[0])||{};
41 return 1 if grep +(!ref($_) and *$_{CODE}), values %$stash;
42 require_module($_[0]);
46 sub _maybe_load_module {
47 return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
48 (my $proto = $_[0]) =~ s/::/\//g;
50 if (eval { require "${proto}.pm"; 1 }) {
51 $MAYBE_LOADED{$_[0]} = 1;
53 if (exists $INC{"${proto}.pm"}) {
54 warn "$_[0] exists but failed to load with error: $@";
56 $MAYBE_LOADED{$_[0]} = 0;
58 return $MAYBE_LOADED{$_[0]};
62 return mro::get_linear_isa($_[0]);
65 sub _install_coderef {
66 *{_getglob($_[0])} = _name_coderef(@_);
70 can_haz_subname ? Sub::Name::subname(@_) : $_[1];
73 sub STANDARD_DESTROY {
80 $self->DEMOLISHALL(in_global_destruction);
86 die $e if $e; # rethrow