|We don't bite newbies here... much|
Perl OO with Class::Structby VinsWorldcom (Parson)
|on Dec 13, 2013 at 14:45 UTC||Need Help??|
VinsWorldcom has asked for the
wisdom of the Perl Monks concerning the following question:
I know object-oriented programming in that I can use others' modules and I've written some of my own. I've read perlobj and perlootut. However, most of my objects have been simply nested Perl data structures (e.g., HoH, HoAoH, etc.). I have no problem creating or accessing those types of objects.
I'm keen to learn more about how to do this more "?correctly?". So I started looking into Class::Struct since it's simple, for building classes and in Perl core.
Take the following code borrowed heavily from the examples in the Class::Struct perldoc:
This works swimmingly until $litter is created like so:
Which of course produces an error ...
... because "1" doesn't have a method - in fact, it's not even an "object". What I really 'think' I need to do is define the Litter object like so:
Meaning the 'cats' method should contain an array of 'Cat' objects, not just an array of anything. The documentation for Class::Struct leads me to believe I can't do it.