Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Trying to understand Perl Objects

by TGI (Parson)
on Apr 06, 2009 at 21:03 UTC ( [id://755857]=note: print w/replies, xml ) Need Help??


in reply to Trying to understand Perl Objects

OOP in Perl has a very strong DIY flavor. As a result, there are all sorts of ways to build your objects in Perl: classical methods with blessed hash or array refs, inside out objects, and even more exotic XS based objects.

You can do all the work yourself each time you write a new OOP module and implement all your accessors and mutators, type validation, and so forth manually. Or you can use one of the many modules to help automate the process.

I have found that two ways of generating object code work well for me.

For dirt simple objects that are used to contain some data and bind a few methods to the data structure, Class::Struct does a very nice job. It is very limited and somewhat brain-dead (eg. can't use it in subclasses), but for very, very simple tasks, it reduces a lot of busy-work, and I can understand exactly what it does.

For anything with more than the most minimal demands, Moose is the way to go. It provides much of the goodness we will see with Perl6 objects. I've used it for a few projects now, and it is really quite amazing.

For an example of why Moose is so great see the Moose Unsweetened document for a comparison of manual and Moose object code.

Perl 6 is not even fully specified, and is certainly not ready for prime time. The Parrot VM just released version 1.0 which provides a stable API for language implementors, but is still not 100% ready for production use--that will come in 2.0. Both projects are cruising along, but both are far from being ready for production use. If you want perl 6 oo, with roles and type checking, etc. Moose is the best way to get it now.


TGI says moo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://755857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found