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?

Browser.pm



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;

EspaceBrowser.pl



#! /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


In reply to Problem with inheritance by kevinp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.