From: Graham Knop Date: Sun, 9 Apr 2017 13:58:13 +0000 (+0200) Subject: clean up module loading X-Git-Tag: v0.31~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=3f3b3137bffa7baf8d1204e7a99d6ab23de4686b clean up module loading --- diff --git a/lib/Config/Any/Base.pm b/lib/Config/Any/Base.pm index 2826cb6..1aff039 100644 --- a/lib/Config/Any/Base.pm +++ b/lib/Config/Any/Base.pm @@ -38,15 +38,16 @@ Lack of specifying these subs will assume you require no extra modules to functi sub is_supported { my ( $class ) = shift; + local $@; if ( $class->can( 'requires_all_of' ) ) { - eval join( '', map { _require_line( $_ ) } $class->requires_all_of ); - return $@ ? 0 : 1; + return eval { + _require($_) for $class->requires_all_of; + 1; + } || 0; } if ( $class->can( 'requires_any_of' ) ) { - for ( $class->requires_any_of ) { - eval _require_line( $_ ); - return 1 unless $@; - } + eval { _require( $_ ); 1 } and return 1 + for $class->requires_any_of; return 0; } @@ -54,11 +55,12 @@ sub is_supported { return 1; } -sub _require_line { +sub _require { my ( $input ) = shift; my ( $module, $version ) = ( ref $input ? @$input : $input ); - return "require $module;" - . ( $version ? "${module}->VERSION('${version}');" : '' ); + (my $file = "$module.pm") =~ s{::}{/}g; + require $file; + $module->VERSION if $version; } =head1 AUTHOR