Umm.. sorry perhaps I didn't make my question clear enough. But take your sample as an example:
use warnings;
use strict;
package One;
require Exporter; # added
our @ISA =qw/Exporter/;# added
our @EXPORT = qw/foo/;# added
sub foo {
print "I'm One::foo >> @_ \n"; # changed
}
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("abc"); # Now foo() has an extra first element in @_
foo("abc"); # die() for Bareword from 'strict subs'
In this case
foo() was not created/designed as a method in
One, but an exported function. From my understanding,
foo() is only visible in
Two, but not
main::. Actually, I can do that like :
package Two;
use base 'One';
require Exporter;
our @EXPORT = qw/foo/;
*foo = \&One::foo;
sub new { ... }
sub newMethod { ... }
sub overrideOldMethod { ... }
But then, I have to declare every function from the base class manually, and if I sub class
Two later, I have to do that again. So, is that anyway I can having both inherit the base class (methods), and also have their exported functions at once?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.