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


In reply to Moo error message not understood by davies

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.