in reply to Re^3: Simple inheritance question
in thread Simple inheritance question
Yeah, $self->test will work (altho this still does not require a constructor for One, seems like a red herring):
Basically, I have two classes that share a bunch of such internal functions (no object required, it's just string parsing), so I thought the best thing would be to have a base class containing those.
In fact Exporter does work, see my reply to jethro.
I guess this is starting to seem a little finnicky, but I would like to use test() as if it were a function internal to Two, not requiring an object.#!/usr/bin/perl -w use strict; { package One; sub test { my $x = pop; print "$x\n"; } } { package Two; use base "One"; sub new { my $self = {}; bless($self); } sub eg { my $self = shift; $self->test(pop); } } my $obj = new Two(); $obj->eg("hello");
Basically, I have two classes that share a bunch of such internal functions (no object required, it's just string parsing), so I thought the best thing would be to have a base class containing those.
In fact Exporter does work, see my reply to jethro.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Simple inheritance question
by BrowserUk (Patriarch) on Apr 23, 2010 at 21:09 UTC | |
Re^5: Simple inheritance question
by ikegami (Patriarch) on Apr 23, 2010 at 20:40 UTC | |
Re^5: Simple inheritance question
by webfiend (Vicar) on Apr 23, 2010 at 17:12 UTC | |
by chromatic (Archbishop) on Apr 23, 2010 at 19:36 UTC |
In Section
Seekers of Perl Wisdom