davies has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use diagnostics; use 5.014; my $newbook = Lib::Book->new( isbn => 'ISBN', ); say $newbook->isbn; package Lib::Book; use Moo; has isbn => ( is => 'rw', ); 1;
My code, in which I can see no material differences from the documentation (http://search.cpan.org/~haarg/Moo-1.004002/lib/Moo.pm), crashes as follows:
Z:\Data\Library\Dancer2>sopw.pl Can't locate object method "isbn" via package "Lib::Book" at Z:\Data\Library\Dancer2\sopw.pl line 9 (#1) (F) You called a method correctly, and it correctly indicated a pa +ckage functioning as a class, but that package doesn't define that parti +cular method, nor does any of its base classes. See perlobj. Uncaught exception from user code: Can't locate object method "isbn" via package "Lib::Book" at Z +:\Data\Library\Dancer2\sopw.pl line 9.
I'm slightly surprised by the error message's reference to an "object method" when I'm trying to address a property, but I suspect that this is merely a Perl idiosyncracy. The assignment in the "new" command works - printing the object using Data::Dumper reveals the isbn property set as I would expect. I tried inserting the "namespace::clean" line from the docs, but that changed nothing.
What should I look at next, please?
Regards,
John Davies
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Moo error message not understood
by tangent (Parson) on Jan 17, 2014 at 18:50 UTC | |
Re: Moo error message not understood (BEGIN block missing)
by Anonymous Monk on Jan 17, 2014 at 17:57 UTC | |
by davies (Prior) on Jan 17, 2014 at 19:35 UTC | |
by Anonymous Monk on Jan 17, 2014 at 20:20 UTC | |
by Anonymous Monk on Jan 17, 2014 at 20:34 UTC | |
Re: Moo error message not understood
by ikegami (Patriarch) on Jan 17, 2014 at 18:28 UTC |
Back to
Seekers of Perl Wisdom