From: Lukas Mai Date: Tue, 5 Feb 2013 02:13:12 +0000 (+0100) Subject: don't load Moo if Moose is already present X-Git-Tag: v1.0101~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c4ca5488efd58ba287abb22a5b24aea9cb4f8f6;p=p5sagit%2FFunction-Parameters.git don't load Moo if Moose is already present --- diff --git a/lib/Function/Parameters/Info.pm b/lib/Function/Parameters/Info.pm index 7767b36..fd8a0ec 100644 --- a/lib/Function/Parameters/Info.pm +++ b/lib/Function/Parameters/Info.pm @@ -4,20 +4,34 @@ use v5.14.0; use warnings; -use Moo; - our $VERSION = '0.02'; +# If Moo isn't loaded yet but Moose is, avoid pulling in Moo and fall back to Moose +my ($Moo, $meta_make_immutable); +BEGIN { + if ($INC{'Moose.pm'} && !$INC{'Moo.pm'}) { + $Moo = 'Moose'; + $meta_make_immutable = sub { $_[0]->meta->make_immutable }; + } else { + require Moo; + $Moo = 'Moo'; + $meta_make_immutable = sub {}; + } + $Moo->import; +} + { package Function::Parameters::Param; - use Moo; + BEGIN { $Moo->import; } use overload fallback => 1, '""' => sub { $_[0]->name }, ; has $_ => (is => 'ro') for qw(name type); + + __PACKAGE__->$meta_make_immutable; } my @pn_ro = glob '{positional,named}_{required,optional}'; @@ -51,6 +65,8 @@ sub args_max { $r } +__PACKAGE__->$meta_make_immutable; + 'ok' __END__