knbknb has asked for the wisdom of the Perl Monks concerning the following question:
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?
The code above is from the Class:Std CPAN documentation (which contains some inconsistencies, by the way.)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; } }
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 | |
by educated_foo (Vicar) on Feb 20, 2009 at 04:31 UTC | |
|
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 | |
by bruno (Friar) on Feb 20, 2009 at 11:38 UTC | |
|
Re: OOP/ Class::Std questions
by knbknb (Acolyte) on Feb 20, 2009 at 08:13 UTC | |
by stvn (Monsignor) on Feb 20, 2009 at 15:43 UTC |