kevinp has asked for the wisdom of the Perl Monks concerning the following question:
I am starting with object oriented Perl and have hit a problem:
I have two files (taken and tweaked from a book on LWP) - see below.
What I am trying to do is inherit from LWP::Simple but I get the error:
Can't locate object method "new" via package "Browser" at ./EspaceBrow +ser.pl line 17.
Both files are in the same directory and @INC shows the directory when printed. Why is it failing to inherit new from LWP?
package Browser; use LWP::Simple; @ISA = "LWP::Simple"; sub notnew { my $class = shift; my $self = { }; return bless $self, $class; } sub name { my $self = shift; $self->{NAME} = shift if @_; return $self->{NAME}; } sub age { my $self = shift; $self->{AGE} = shift if @_; return $self->{AGE}; } 1;
#! /usr/bin/perl -w use strict; use warnings; use FindBin; use lib $FindBin::Bin; use Browser; foreach my $x ( @INC ) { print "$x\n"; } my $dude = Browser->new(); $dude->name("Jason"); $dude->age(23); printf "%s is age %d.\n", $dude->name, $dude->age;
Edit: g0n - code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with inheritance
by Sidhekin (Priest) on Oct 24, 2007 at 20:52 UTC | |
|
Re: Problem with inheritance
by gamache (Friar) on Oct 24, 2007 at 20:53 UTC | |
by ikegami (Patriarch) on Oct 24, 2007 at 21:07 UTC | |
by kevinp (Novice) on Oct 24, 2007 at 21:05 UTC |