Hello monks,
Hopefully someone can alleviate my confusion w.r.t. when to use Exporter/@ISA when subclassing.
My code - which works as expected:
package MyClass::A;
use strict;
use warnings;
use Exporter;
use base qw(Net::Server::PreFork);
#our @ISA = qw(Exporter);
our @EXPORT = qw(new serve);
our @EXPORT_OK = qw();
sub new
{
my ($class_name) = @_;
my $self = {};
bless $self, $class_name;
#...
return $self;
}
sub process_request
{
#...
}
sub serve
{
my ($self) = @_;
MyClass::A->run();
return $self;
}
my $s = MyClass::A->new();
$s->serve();
However, if I uncomment
#our @ISA = qw(Exporter);
Then I get the error
Can't locate object method "run" via package "MyClass::A" at b.pl line
+ 28.
I normally create all my classes using our @ISA = qw(Exporter);, so I'm not clear on why this is failing now. Is it because I'm sub-classing Net::Server::PreFork?
Second - and I suppose related - question is that if I comment out as follows:
#use Exporter;
use base qw(Net::Server::PreFork);
#our @ISA = qw(Exporter);
everything still works normally, so why on earth should I bother with Exporter anyway?
Thanks
-
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.
|