module - Why do `perl Foo.pm` and `perl -I. -mFoo -e1` behave differently? -


with code in foo.pm:

use strict; use warnings; package foo;  begin {   $foo::authority = 'cpan:ether'; } 1; 

loading file module gives no errors:

$ perl -i. -mfoo -e1 $ 

and yet, loading file directly does:

$ perl foo.pm name "foo::authority" used once: possible typo @ foo.pm line 6. 

moreover, perl -e'require "foo.pm"' not warn.

why there difference? file being parsed differently, how , why?

"why" technical point of view, or language design point of view?

from language point of view, makes sense because variable referred within module may part of module's public api. example, data::dumper exposes bunch of package variables alter behaviour. (arguably bad design, ho hum.) these variables might referred once in module, can potentially referred other parts of program.

if it's referred in main script once, , no modules refer it, it's more mistake, warning within script, not in module.

from technical point of view, warning generated gv.c. can't make head nor tail of exact conditions under it's triggered.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -