|We don't bite newbies here... much|
Can't call method "MoveBook" on an undefined valueby bgu (Novice)
|on Jan 24, 2013 at 17:55 UTC||Need Help??|
bgu has asked for the
wisdom of the Perl Monks concerning the following question:
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.pm
Main.pl - already have a ref to a list of books saved in $allbooks. Please note that the second attribute, read_books, is not initializedmy $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 :)