klekker has asked for the wisdom of the Perl Monks concerning the following question:
Son.pmpackage Father; use warnings; use strict; sub new { my $class = shift; my $self = {}; bless ($self, $class); return $self; } # INTERFACE sub aText { #implement die('Parent aText'); } sub aList { # implement die('Parent aList'); } 1;
test.plpackage Son; use warnings; use strict; use Father; use base qw(Father); use constant { aText => 'This is a Text', aList => [qw(aaa bbb ccc)], }; sub print_son { my $self = shift; print 'Son:', $self->aText(), "\n"; print 'Son: ', join(', ', @{$self->aList()}), "\n"; } 1;
Output:#! /usr/bin/perl use strict; use warnings; use Son; my $s = Son->new(); print $s->aText(), "\n"; print join(', ', @{$s->aList()}), "\n"; $s->print_son();
This is a Text aaa, bbb, ccc Son:This is a Text Son: aaa, bbb, ccc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using constant to override (abstract) methods.
by moritz (Cardinal) on Mar 28, 2011 at 08:40 UTC | |
by klekker (Pilgrim) on Mar 28, 2011 at 10:30 UTC | |
|
Re: Using constant to override (abstract) methods.
by ELISHEVA (Prior) on Mar 28, 2011 at 09:39 UTC | |
by klekker (Pilgrim) on Mar 28, 2011 at 10:27 UTC | |
by chromatic (Archbishop) on Mar 29, 2011 at 05:10 UTC | |
by klekker (Pilgrim) on Mar 31, 2011 at 11:54 UTC |