Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Simple inheritance question

by jethro (Monsignor)
on Apr 23, 2010 at 16:29 UTC ( #836558=note: print w/replies, xml ) Need Help??

in reply to Simple inheritance question

If test() were included in Two's namespace, Two could not override it with its own test() if needed.

UPDATE: You can use Exporter to add test to Two's namespace if you like. After all a class is just a package

Replies are listed 'Best First'.
Re^2: Simple inheritance question
by halfcountplus (Hermit) on Apr 23, 2010 at 16:59 UTC
    Yeah, that does it:
    #!/usr/bin/perl -w use strict; { package One; use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(test); sub test { my $x = pop; print "$x\n"; } } { package Two; use base "One"; sub new { One->import; my $self = {}; bless($self); } sub eg { test(pop); } } my $obj = new Two(); $obj->eg("hello");
    Thanks all!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://836558]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2021-04-12 17:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found