in reply to Calling SUPER::new from classes built with Class::MethodMaker?
I'd go with the init() function. One can call the superclass' $self->SUPER::init(@_) from that.
Just my 2 cents, -gjb-
For an example, see below:
Parent class:
package Parent; use strict; use warnings; use Class::MethodMaker new_hash_init => 'new', get_set => [qw( color )]; sub init { my $self = shift(); print STDERR "initializing parent\n"; my %values = @_; $self->color($values{color}); } 1;
Child class:
package Child; use strict; use warnings; use Class::MethodMaker new_hash_init => 'new', get_set => [qw( shape )]; use base qw( Parent ); sub init { my $self = shift(); my %values = @_; $self->SUPER::init(color => ($values{color})); $self->shape($values{shape} || 'square'); } 1;
Main program:
use strict; use warnings; use Parent; use Child; my $p = new Parent(color => 'green'); my $c = new Child(shape => 'round', color => 'red'); print $p->color(), "\n"; print $c->color(), ", ", $c->shape(), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Calling SUPER::new from classes built with Class::MethodMaker?
by Anonymous Monk on Feb 12, 2003 at 01:34 UTC | |
by bbfu (Curate) on Jul 09, 2003 at 05:18 UTC | |
by danb (Friar) on Jul 05, 2003 at 23:43 UTC |