Commit | Line | Data |
b1eebd55 |
1 | package Moo::_Utils; |
6c74d087 |
2 | |
3 | use strictures 1; |
4 | use base qw(Exporter); |
5 | |
daa05b62 |
6 | our @EXPORT = qw(_getglob _install_modifier _maybe_load_module); |
6c74d087 |
7 | |
8 | sub _getglob { no strict 'refs'; \*{$_[0]} } |
9 | |
10 | sub _install_modifier { |
6c74d087 |
11 | my ($into, $type, $name, $code) = @_; |
12 | my $ref = ref(my $to_modify = $into->can($name)); |
a165a07f |
13 | |
9187b862 |
14 | require Sub::Defer; |
15 | Sub::Defer::undefer_sub($to_modify); |
a165a07f |
16 | |
9187b862 |
17 | require Class::Method::Modifiers; |
6c74d087 |
18 | Class::Method::Modifiers::install_modifier(@_); |
19 | } |
20 | |
daa05b62 |
21 | our %MAYBE_LOADED; |
22 | |
23 | sub _maybe_load_module { |
24 | return $MAYBE_LOADED{$_[0]} if exists $MAYBE_LOADED{$_[0]}; |
25 | (my $proto = $_[0]) =~ s/::/\//g; |
26 | if (eval { require "${proto}.pm"; 1 }) { |
27 | $MAYBE_LOADED{$_[0]} = 1; |
28 | } else { |
29 | if (exists $INC{"${proto}.pm"}) { |
30 | warn "$_[0] exists but failed to load with error: $@"; |
31 | } |
32 | $MAYBE_LOADED{$_[0]} = 0; |
33 | } |
34 | return $MAYBE_LOADED{$_[0]}; |
35 | } |
36 | |
6c74d087 |
37 | 1; |