From e6ac6ca46dec80ef67e0c2efb21a412ff210b923 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 31 Mar 2020 16:53:58 +0300 Subject: Fix duplicate load prevention * lib/Example/Foobar/list.pm: strip location-specific parts of the pathname before looking up in %INC and loading. * lib/Example/Foobar.pm: Minor stylistic change. --- lib/Example/Foobar.pm | 6 +----- lib/Example/Foobar/list.pm | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'lib/Example') diff --git a/lib/Example/Foobar.pm b/lib/Example/Foobar.pm index 3ba4824..05ec036 100644 --- a/lib/Example/Foobar.pm +++ b/lib/Example/Foobar.pm @@ -57,11 +57,7 @@ sub new { my $modpath = $modname; $modpath =~ s{::}{/}g; $modpath .= '.pm'; - my $cmd; - eval { - require $modpath; - $cmd = $modname->new(@args); - }; + my $cmd = eval { require $modpath; $modname->new(@args) }; if ($@) { if ($@ =~ /Can't locate $modpath/) { die "unknown command: $command\n" diff --git a/lib/Example/Foobar/list.pm b/lib/Example/Foobar/list.pm index 1096c03..f4b02a8 100644 --- a/lib/Example/Foobar/list.pm +++ b/lib/Example/Foobar/list.pm @@ -52,12 +52,13 @@ sub run { foreach my $mod (sort map { my $name = basename($_); - if (exists($INC{File::Spec->catfile($self->classpath, - $name)})) { + my $filename = File::Spec->catfile($self->classpath, + $name); + if (exists($INC{$filename})) { () } else { eval { - require $_; + require $filename; }; $name =~ s/\.pm$//; $@ ? () : [$name, $_]; -- cgit v1.2.1