in reply to
import doesn't work at runtime?
You're missing some parenthesis and some strictures to explain the problem. Without parens:
perl -e 'use strict; use warnings; require MyModule; MyModule->import(
+qw(frobnicate munge)); frobnicate; munge; '
Bareword "frobnicate" not allowed while "strict subs" in use at -e lin
+e 1.
Bareword "munge" not allowed while "strict subs" in use at -e line 1.
Execution of -e aborted due to compilation errors.
With:
perl -e 'use strict; use warnings; require MyModule; MyModule->import(
+qw(frobnicate munge)); frobnicate(); munge(); '
frobnicated!
munged!
With parens, Perl knows at compile time that frobnicate()/munge() are subroutines
and that Perl can deal with them later at runtime. So, the following also works, but changes
the semantics a bit (first argument is "MyModule") - Perl still detects the subroutine invocation (w/o parens):
perl -e 'use strict; use warnings; require MyModule; MyModule->import(
+qw(frobnicate munge)); MyModule->frobnicate; MyModule->munge; '
frobnicated!
munged!