bgu has asked for the wisdom of the Perl Monks concerning the following question:
Hi there,
I am new to Moose and I could use a little help on how to fix this.
FYI, I completely agree with the error, just need suggestions on how to fix the code.
The code models somebody's library, with books that the owner has read and books that he has not. At the beginning, all books are meant to be 'unread', and as he starts reading, he moves them into the 'read' pile.
LibraryTest.pmpackage LibraryTest; use Moose; use Book; has 'unread_books' => (isa => 'ArrayRef[Book]', is =>'rw' ); has 'read_books' => (isa => 'ArrayRef[Book]', is =>'rw' );
Main.pl - already have a ref to a list of books saved in $allbooks. Please note that the second attribute, read_books, is not initialized
my $Libr = LibraryTest->new(unread_books => $allbooks);....he reads the first book and wants to move it from the unread pile to the read pile...
$Libr->MoveBook($Libr->PopBook);This is where disaster strucks .. the second attribute of the object is undef... how do I initialize it with a reference to an empty array of Book?
Or maybe it's better to modify the constructor somehow so that for when the second attribute is not explicitly given ?
Many thanks for any suggestion :)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can't call method "MoveBook" on an undefined value
by tobyink (Canon) on Jan 24, 2013 at 19:52 UTC | |
Re: Can't call method "MoveBook" on an undefined value
by davido (Cardinal) on Jan 24, 2013 at 18:45 UTC | |
Re: Can't call method "MoveBook" on an undefined value
by kcott (Archbishop) on Jan 24, 2013 at 18:59 UTC | |
Re: Can't call method "MoveBook" on an undefined value
by thargas (Deacon) on Jan 25, 2013 at 15:50 UTC |