I've read through almost all of the Moose docs I could find on CPAN and several
of the Moose slide decks floating around the Interwebs.
That being said I have some basic questions that probably have simple answers.
Maybe I didn't read the fine manuals closely enough, so if I did overlook
something, please point me toward the right spot in the docs and I'll figure it
out.
That being said here are my questions:
1) In the "old style" OO (which I have used for a long time now) I would do
something like this:
I would make a file called "Account.pm" and try to encapsulate all of the
functionality of accounts in that one file.
I would make another file called Server.pm and encapsulate functionality around
servers in the other file. Then if Account and Server have a relationship, I
would do this:
package Account;
use Server;
I found that if I do this:
package Server; # (in a file called Server.pm)
use Moose;
has 'name' => {
is => 'ro',
isa => 'Str',
};
# etc
package Account; # (in a file called Account.pm)
use Moose;
use Server;
has 'server' => {
is => 'ro',
isa => 'Server',
};
perl -wc Account.pm throws an error
but if I change "use" to "require Server;" I do not get an error.
Why doesn't use work?
2) Maybe I haven't really grokked the Moose Way yet, but what's the best way to
implement a collection of Moose Objects?
In the old style OO, I would implement an object as, say, Account.pm and then I
would create a collection class of that object type called XXXCollection or
AccountCollection.pm in this case. I usually stored individual objects as a
hash of hashes, using the object name as the key.
I suspect that Roles and Traits can help me write a Collection class trivially
where I will get a lot of functionality "for free" but I'm just not quite sure
I understand the docs well enough to put it all together.
Thanks for any help/pointers.
--Mark
Mark Allen