perlquestion
smullis
<p>Hi All,</p>
<p>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...</p>
<p>I have no doubt that the following question is extremely basic..</p>
<p>I want to extend a class for a Perl API with one additional method.</p>
<p>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.</p>
So, to test this:
filename: SPEAK/ITALIAN.pm
<code>
package 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;
</code>
<p>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</p>
filename: test.pl
<code>
#!/usr/bin/perl
use strict;
use warnings;
use SPEAK::ITALIAN;
sub goodbye{
print GOODBYE . " in Italiano\n";
}
hello();
goodbye();</code>
Running this gives:
<code>Hello in Italiano!
GOODBYE in Italiano!</code>
<p>As you've noticed, GOODBYE is incorrect. It's not picking up the constant from the SPEAK::ITALIAN module.</p>
<p>I know I'm missing something very basic. Do I need "use base qw(SPEAK::ITALIAN)"?</p>
<p>Any pointers?</p>
<p>Thanks in advance and apologies for the awfulness of the question...</p>
<p>S</p>