3 sub _getglob { \*{$_[0]} }
4 sub _getstash { \%{"$_[0]::"} }
7 *lt_5_8_3 = $] < 5.008003
14 use base qw(Exporter);
16 our @EXPORT = qw(_getglob _install_modifier _load_module _maybe_load_module);
18 sub _install_modifier {
19 my ($into, $type, $name, $code) = @_;
21 if (my $to_modify = $into->can($name)) { # CMM will throw for us if not
23 Sub::Defer::undefer_sub($to_modify);
26 Class::Method::Modifiers::install_modifier(@_);
31 # _load_module is inlined in Role::Tiny - make sure to copy if you update it.
34 (my $proto = $_[0]) =~ s/::/\//g;
35 return 1 if $INC{"${proto}.pm"};
36 # can't just ->can('can') because a sub-package Foo::Bar::Baz
37 # creates a 'Baz::' key in Foo::Bar's symbol table
38 return 1 if grep !/::$/, keys %{_getstash($_[0])||{}};
39 require "${proto}.pm";
43 sub _maybe_load_module {
44 return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]};
45 (my $proto = $_[0]) =~ s/::/\//g;
46 if (eval { require "${proto}.pm"; 1 }) {
47 $MAYBE_LOADED{$_[0]} = 1;
49 if (exists $INC{"${proto}.pm"}) {
50 warn "$_[0] exists but failed to load with error: $@";
52 $MAYBE_LOADED{$_[0]} = 0;
54 return $MAYBE_LOADED{$_[0]};