3 no warnings 'once'; # guard against -w
5 sub _getglob { \*{$_[0]} }
6 sub _getstash { \%{"$_[0]::"} }
9 *lt_5_8_3 = $] < 5.008003
16 use Module::Runtime qw(require_module);
17 use base qw(Exporter);
21 _getglob _install_modifier _load_module _maybe_load_module
22 _get_linear_isa _getstash
25 sub _install_modifier {
26 my ($into, $type, $name, $code) = @_;
28 if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
30 Sub::Defer::undefer_sub($to_modify);
33 Class::Method::Modifiers::install_modifier(@_);
39 (my $proto = $_[0]) =~ s/::/\//g;
40 return 1 if $INC{"${proto}.pm"};
41 # can't just ->can('can') because a sub-package Foo::Bar::Baz
42 # creates a 'Baz::' key in Foo::Bar's symbol table
43 my $stash = _getstash($_[0])||{};
44 return 1 if grep +(!ref($_) and *$_{CODE}), values %$stash;
45 require_module($_[0]);
49 sub _maybe_load_module {
50 return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
51 (my $proto = $_[0]) =~ s/::/\//g;
53 if (eval { require "${proto}.pm"; 1 }) {
54 $MAYBE_LOADED{$_[0]} = 1;
56 if (exists $INC{"${proto}.pm"}) {
57 warn "$_[0] exists but failed to load with error: $@";
59 $MAYBE_LOADED{$_[0]} = 0;
61 return $MAYBE_LOADED{$_[0]};
65 return mro::get_linear_isa($_[0]);
68 our $_in_global_destruction = 0;
69 END { $_in_global_destruction = 1 }
71 sub STANDARD_DESTROY {
78 $self->DEMOLISHALL($_in_global_destruction);
84 die $e if $e; # rethrow