in reply to Inherit parent, AND also import parent's exported sub ??
You can do this by using the SUPER pseudo-class. Here's an example:
use warnings; use strict; package One; sub foo { print "I'm One::foo()\n"; } package Two; use base 'One'; sub new { return bless {}, shift; } sub foo { my $self = shift; print "I'm Two::foo(). I'm going to call " . "my Parent's foo()...\n"; $self->SUPER::foo(); } package main; my $obj = Two->new; $obj->foo();
Output:
I'm Two::foo(). I'm going to call my Parent's foo()... I'm One::foo()
See perlobj.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inherit parent, AND also import parent's exported sub ??
by exilepanda (Friar) on Sep 08, 2016 at 19:53 UTC | |
by Anonymous Monk on Sep 08, 2016 at 20:39 UTC | |
by exilepanda (Friar) on Sep 09, 2016 at 11:23 UTC | |
by stevieb (Canon) on Sep 10, 2016 at 00:52 UTC |