smullis has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
It's been years since I posted here... I've been away with the fairies in Python and Ruby land for so long I've forgotten almost everything I ever knew about Perl OO...
I have no doubt that the following question is extremely basic..
I want to extend a class for a Perl API with one additional method.
I have the method but I don't want to edit the core API files. I would like to simply add the method in my script.
So, to test this: filename: SPEAK/ITALIAN.pmpackage SPEAK::ITALIAN; use strict; use warnings; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw( Exporter ); @EXPORT = qw(hello); use constant HELLO => "Hello"; use constant GOODBYE => "Goodbye"; sub hello { print HELLO . " in Italiano\n"; } return 1;
Now, in my script (in this case "test.pl") I simply want to add a method to the SPEAK::ITALIAN class with all constants and other good stuff in the correct namespaces and so on
filename: test.plRunning this gives:#!/usr/bin/perl use strict; use warnings; use SPEAK::ITALIAN; sub goodbye{ print GOODBYE . " in Italiano\n"; } hello(); goodbye();
Hello in Italiano! GOODBYE in Italiano!
As you've noticed, GOODBYE is incorrect. It's not picking up the constant from the SPEAK::ITALIAN module.
I know I'm missing something very basic. Do I need "use base qw(SPEAK::ITALIAN)"?
Any pointers?
Thanks in advance and apologies for the awfulness of the question...
S
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Very basic package / module question...
by almut (Canon) on Feb 05, 2010 at 15:52 UTC | |
by smullis (Pilgrim) on Apr 06, 2011 at 11:27 UTC | |
Re: Very basic package / module question...
by CountZero (Bishop) on Feb 05, 2010 at 16:28 UTC | |
Re: Very basic package / module question...
by rir (Vicar) on Feb 05, 2010 at 16:30 UTC | |
Re: Very basic package / module question...
by pileofrogs (Priest) on Feb 05, 2010 at 20:49 UTC | |
by smullis (Pilgrim) on Feb 08, 2010 at 12:28 UTC |