<?xml version="1.0" encoding="windows-1252"?>
<node id="1015201" title="Can't call method &quot;MoveBook&quot; on an undefined value" created="2013-01-24 12:55:09" updated="2013-01-24 12:55:09">
<type id="115">
perlquestion</type>
<author id="956810">
bgu</author>
<data>
<field name="doctext">
&lt;p&gt;Hi there, &lt;/p&gt;
&lt;p&gt;I am new to Moose and I could use a little help on how to fix this. &lt;/p&gt;
&lt;p&gt;FYI, I completely agree with the error, just need suggestions on how to fix the code.&lt;/p&gt;
&lt;p&gt;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.
&lt;/p&gt;
LibraryTest.pm
&lt;c&gt;package LibraryTest;
use Moose;
use Book;

has 'unread_books' =&gt; (isa =&gt; 'ArrayRef[Book]', is =&gt;'rw' );
has 'read_books' =&gt; (isa =&gt; 'ArrayRef[Book]', is =&gt;'rw' );
&lt;/c&gt;
&lt;p&gt;
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 &lt;/p&gt;
&lt;c&gt;my $Libr = LibraryTest-&gt;new(unread_books =&gt; $allbooks); &lt;/c&gt;

&lt;p&gt;....he reads the first book and wants to move it from the unread pile to the read pile...&lt;/p&gt;

&lt;c&gt;$Libr-&gt;MoveBook($Libr-&gt;PopBook);&lt;/c&gt;

&lt;p&gt;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?&lt;/p&gt;
&lt;p&gt;Or maybe it's better to modify the constructor somehow so that for when the second attribute is not explicitly given ?&lt;/p&gt;
Many thanks for any suggestion :)

</field>
</data>
</node>
