Closed bbkr closed 8 years ago
use A
is roughly the same as require A; A->import
. (see perlfunc, perlmod, and Exporter for details).
As you put has 'import'
in the package A, when you use A
, your "import" is called (A->import
), and your "import" is an accessor which expects the caller is an object, the said error is triggered because the caller is a class ("A") in this case. If you do need to write has 'import'
, try require A
or use A ()
not to call import
method automatically.
In the one-liner you mentioned, package A is not actually "use"d, so A->import
is not called either. If you write A.pm, and "use" it from an one-liner, you'll see the same error.
This is not a bug in Mouse (or Moose and its friends).
Thanks for detailed explanation! I'm closing the issue.
A.pm file:
Usage:
This error is tricky because syntax is correct (checked with
perl -c
) and bug can _not_ be reproduced as oneliner (perl -e 'package A; use Mouse; has "import" => ("is" => "ro", "isa" => "Int", "default" => 42); package main; print A->new->import'
works just fine).Mouse version 2.4.5.