You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nguyen Vu Hung <vu...@cnt.mxt.nes.nec.co.jp> on 2007/08/16 02:57:33 UTC

Class inheritance, and SUPER under mod_perl2

Hello all,

I am quite new to Perl, mod_perl and mod_perl2 so please excuse me for
my questions. It my sounds noobish.

In the code below, the class XXX:YYY3 inherits Net::Cmd,
IO::Socket::Inet, create an object $obj with the SUPER keyword.

As far as I know, this code works well under Apache 1.3, Perl 5.6,
mod_perl 1.3.

But in current environment which consists Apache 2.0.52, Perl 5.8,
mod_perl 2.0.3, $obj becomes undefined (!!) after it is called with SUPER.

Anyone gets any clues?

Here is the code:

------------------

package XXX::YYY3;

@ISA = qw(Net::Cmd IO::Socket::INET);

sub new
{
my $self = shift;
my $type = ref($self) || $self;

my $hosts = "localhost";
my $obj;
my @localport = ();

my $h;
foreach $h (@{$hosts})
{
$obj = $type->SUPER::new(PeerAddr => ($h),
PeerPort => 110,
Proto => 'tcp',
LocalPort => 110,
Timeout => 120
) and last;
}


# obj is undefined now. why?
unless ( defined $obj ) {
$sl->log_serror(__FILE__, __LINE__, Apache2::Const::LOG_ERR,
APR::Const::SUCCESS, "XXX:: undef obj! ERROR. ");
}

# vuhung
# ref: http://www.perlmonks.org/?node_id=495975
return undef
unless defined $obj;

}


Re: Class inheritance, and SUPER under mod_perl2

Posted by Perrin Harkins <pe...@elem.com>.
On 8/15/07, Nguyen Vu Hung <vu...@cnt.mxt.nes.nec.co.jp> wrote:
> In the code below, the class XXX:YYY3 inherits Net::Cmd,
> IO::Socket::Inet, create an object $obj with the SUPER keyword.
>
> As far as I know, this code works well under Apache 1.3, Perl 5.6,
> mod_perl 1.3.
>
> But in current environment which consists Apache 2.0.52, Perl 5.8,
> mod_perl 2.0.3, $obj becomes undefined (!!) after it is called with SUPER.

I don't think this is related to SUPER, since mod_perl doesn't affect
that.  You can confirm this by hard-coding the name of the superclass
instead of the word SUPER, e.g.

    $obj = $type->IO::Socket::INET::new( ...etc...

- Perrin