knbknb has asked for the wisdom of the Perl Monks concerning the following question:

Honorable Monks,

Can anyone point me to a little open-source project where the Class::Std object system was used. I'd like to get some inspiration on how code using this looks like in real life.

Currently I am not using Class::Std in production, although I have spent some time recently to create something like a code generator for classes using this object system.

Now I have a question regarding object attributes (such as %name_of, %patent_of in the code below) in a base class. These are not inherited to the derived classes,are they? It seems to me that I cannot access the values of object attibutes of a parent class from within the derived class.

Is use of SUPER disallowed generally in Class:Std?

Must I always redeclare those attributes ( at least those that I intend to use) in the derived class? Wouldn't this result in code duplication?

package Wax::Floor; use Class::Std; { my %name_of :ATTR( init_arg => 'name' ); my %patent_of :ATTR( init_arg => 'patent' ); sub describe :CUMULATIVE { my ($self) = @_; print "The floor wax $name_of{ident $self} ", "(patent: $patent_of{ident $self})\n"; return; } } package Topping::Dessert; use Class::Std; { my %name_of :ATTR( init_arg => 'name' ); my %flavour_of :ATTR( init_arg => 'flavour' ); sub describe :CUMULATIVE { my ($self) = @_; print "The dessert topping $name_of{ident self}", "with that great $flavour_of{ident $self} taste!\n"; return; } } package Shimmer; use base qw( Wax::Floor Topping::Dessert ); use Class::Std; { my %name_of :ATTR( init_arg => 'name' ); my %patent_of :ATTR( init_arg => 'patent' ); sub describe :CUMULATIVE { my ($self) = @_; print "New $name_of{ident $self} (patent: $patent_of{ident + $self})\n", "Combining...\n"; return; } }
The code above is from the Class:Std CPAN documentation (which contains some inconsistencies, by the way.)

I know that Moose is a popular object system. I might indeed try it at a later time.

Replies are listed 'Best First'.
Re: OOP/ Class::Std questions
by perrin (Chancellor) on Feb 19, 2009 at 17:25 UTC
    Class::Std basically isn't used in real life. If you want an inside-out object system, the one to use is Object::InsideOut. However, I'd say it's pointless to use anything other than Moose these days if you need more than you can get from simple things like Class::Accessor.
      ...which you probably don't. If your requirements or whims are severely OO, either Mouse or the heavier Moose is the way to go, but remember that Perl's distinguishing characteristic is "TIMTOWDI." "Doing it" is the most important part; "how" is a matter of personal preference.
Re: OOP/ Class::Std questions
by stvn (Monsignor) on Feb 19, 2009 at 19:12 UTC
Re: OOP/ Class::Std questions
by Anonymous Monk on Feb 20, 2009 at 08:05 UTC
    Thanks for answering!

    Last night I have looked into Moose (starting with reading Randal Schwartz's two Articles on stonehenge.com; and two articles from the cookbook), and it seems to be easier than expected. And the code for my classes generated is very small, smaller than with Class:Std.

    Is there a "Moose for Java Programmers" introductory article somewhere? I am not a java programmer but I find myself building analogies to Java's language constructs all the time.

Re: OOP/ Class::Std questions
by knbknb (Acolyte) on Feb 20, 2009 at 08:13 UTC
    Ooops... the comment above (?) by anonymous monk was by me, knbknb.

    Forgot to login.

    Maybe I'll subscribe to the moose mailing list to clarify upcoming questions about moose.

      The mailing list is still pretty low traffic, but we try and respond quickly. If you really want immediate feedback and/or help, I suggest joining the #moose IRC channel on irc.perl.org.

      Regarding a "Moose for Java Programmers", no we don't have one of those but that might not be a bad idea, some kind of "Moose for $your_language_here Programmers" series.

      -stvn