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 base qw(Exporter);
17 _getglob _install_modifier _load_module _maybe_load_module
18 _get_linear_isa _getstash _install_coderef _name_coderef
21 sub _install_modifier {
22 my ($into, $type, $name, $code) = @_;
24 if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
26 Sub::Defer::undefer_sub($to_modify);
29 Class::Method::Modifiers::install_modifier(@_);
35 (my $proto = $_[0]) =~ s/::/\//g;
36 return 1 if $INC{"${proto}.pm"};
37 # can't just ->can('can') because a sub-package Foo::Bar::Baz
38 # creates a 'Baz::' key in Foo::Bar's symbol table
39 my $stash = _getstash($_[0])||{};
40 return 1 if grep +(!ref($_) and *$_{CODE}), values %$stash;
41 require_module($_[0]);
45 sub _maybe_load_module {
46 return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
47 (my $proto = $_[0]) =~ s/::/\//g;
49 if (eval { require "${proto}.pm"; 1 }) {
50 $MAYBE_LOADED{$_[0]} = 1;
52 if (exists $INC{"${proto}.pm"}) {
53 warn "$_[0] exists but failed to load with error: $@";
55 $MAYBE_LOADED{$_[0]} = 0;
57 return $MAYBE_LOADED{$_[0]};
61 return mro::get_linear_isa($_[0]);
64 sub _install_coderef {
65 *{_getglob($_[0])} = _name_coderef(@_);
69 can_haz_subname ? Sub::Name::subname(@_) : $_[1];
72 our $_in_global_destruction = 0;
73 END { $_in_global_destruction = 1 }
75 sub STANDARD_DESTROY {
82 $self->DEMOLISHALL($_in_global_destruction);
88 die $e if $e; # rethrow