test hashref arg for new
[gitmo/Role-Tiny.git] / lib / Moo / _Utils.pm
CommitLineData
b1eebd55 1package Moo::_Utils;
6c74d087 2
3use strictures 1;
4use base qw(Exporter);
5
daa05b62 6our @EXPORT = qw(_getglob _install_modifier _maybe_load_module);
6c74d087 7
8sub _getglob { no strict 'refs'; \*{$_[0]} }
9
10sub _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 21our %MAYBE_LOADED;
22
23sub _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 371;