The eval is because the regexp might match a package name
I knew there was a reason like that but was puzzled when it worked without eval. Thanks for explaining. I forget to load modules and -ML is less punishment so you can imagine how much I like L! I wonder why Perl doesn't use the failure to load a method or function, because the module isn't loaded, as an opportunity to look for it and load it. For example:
perl -e 'Foo->bar'
Can't locate object method "bar" via package "Foo" (perhaps you forgot to load "Foo"?) at -e line 1. (Perhaps Perl, or perhaps *you* forgot to load "Foo" so object method "bar" can be located? ;-)
perl -e 'print qq~package Foo; sub bar { print "baz\\n" } 1\n~' > Foo.
+pm; cat Foo.pm
package Foo; sub bar { print "baz\n" } 1
perl -I. -MFoo -e 'Foo->bar'
baz
perl -I. -ML -e 'Foo->bar'
baz
I can hack away -M Perl, to locate object method "bar" via package "Foo", why wont you?!
perl -I. -e 'eval{Foo->bar};$_=$@;s/.*forgot to load "([^"]+)".*/$1/s;
+eval{require"$_.pm"};Foo->bar'
baz
And minimize L, to see what's happening, to X.pm:
perl -e 'print qq~package X; { package UNIVERSAL; our \$AUTOLOAD; sub
+AUTOLOAD { warn "\$AUTOLOAD" }} 9\n~' > X.pm; cat X.pm
package X; { package UNIVERSAL; our $AUTOLOAD; sub AUTOLOAD { warn "$AUTOLOAD" }} 9
perl -I. -MX -e ''
I don't know what this means:
IO::File::DESTROY at X.pm line 1.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
But this!
perl -I. -MX -e 'Foo->bar'
Yes
IO::File::DESTROY at X.pm line 1.
Foo::bar at X.pm line 1.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
IO::File::DESTROY at X.pm line 1 during global destruction.
I know what line 2 means! Perl knows what it means. Why doesn't she connect the dots automatically? I guess it would lead to all sorts of chaos and... L! Is L searching @INC in the background with Module::Load to find Foo.pm (and say Bar->foo that doesn't exist), and that's somehow dangerous (according to L docs)? |