3 sub _getglob { \*{$_[0]} }
4 sub _getstash { \%{"$_[0]::"} }
7 *lt_5_8_3 = $] < 5.008003
14 use base qw(Exporter);
18 _getglob _install_modifier _load_module _maybe_load_module
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
26 { local $@; require Sub::Defer; }
27 Sub::Defer::undefer_sub($to_modify);
30 Class::Method::Modifiers::install_modifier(@_);
35 # _load_module is inlined in Role::Tiny - make sure to copy if you update it.
38 (my $proto = $_[0]) =~ s/::/\//g;
39 return 1 if $INC{"${proto}.pm"};
40 # can't just ->can('can') because a sub-package Foo::Bar::Baz
41 # creates a 'Baz::' key in Foo::Bar's symbol table
42 return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
43 { local $@; require "${proto}.pm"; }
47 sub _maybe_load_module {
48 return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
49 (my $proto = $_[0]) =~ s/::/\//g;
51 if (eval { require "${proto}.pm"; 1 }) {
52 $MAYBE_LOADED{$_[0]} = 1;
54 if (exists $INC{"${proto}.pm"}) {
55 warn "$_[0] exists but failed to load with error: $@";
57 $MAYBE_LOADED{$_[0]} = 0;
59 return $MAYBE_LOADED{$_[0]};
63 return mro::get_linear_isa($_[0]);
66 our $_in_global_destruction = 0;
67 END { $_in_global_destruction = 1 }
69 sub STANDARD_DESTROY {
76 $self->DEMOLISHALL($_in_global_destruction);
82 die $e if $e; # rethrow