[LA.pm] Classes with heterogeneous objects?

Mike MacKenzie mackenziemikebus at yahoo.com
Fri Mar 2 19:22:26 PST 2012


Hi Mongers,


Even after all these years, Perl sometimes surprises me.  I just realized today that there is nothing preventing you from creating a class whose instances are implemented heterogeneously.  Your constructor could return a blessed scalar sometimes, a blessed hash under other conditions and a CODE ref at other times.  All would be instances of the same class.  Now I just need to think of a use case for such a thing.

Can any of you guys think of an interesting use case for a class that creates objects with disparate internal structures like this?   Or do you know of an existing module that does this?

Mike MacKenzie



More information about the Losangeles-pm mailing list