thekestrel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I'm trying to converting a script into a package using Exporter and my namespace seems to be getting poluted and I'm not sure why. An example that shows the issue...

#!/usr/bin/perl use strict; use warnings; use mymodule; my $m = mymodule->new(); print "My Test\n"; $m->Func1(); $m->Func2("Fluffy", 5);
package mymodule; require Exporter; use strict; use warnings; our @ISA = qw (Exporter); our @EXPORT = qw(); our @EXPORT_OK qw(Func1); our $VERSION = 0.01; sub new { my $class = shift; my $self = {}; bless ($self, $class); return $self; } sub Func1 { print "Hi there\n"; } sub Func2 { my ($class, $name, $value) = @_; print "hi $name, value $value\n"; }
Gives the following output...
My Test Hi there hi Fluffy, value 5

I've read as many of the related posts and articles I can find on the subject and using the Exporter module is what I want as it is supposed isolate the exposed subroutines and variables through the EXPORT and EXPORT_OK methods. From what I can tell the above code 'should' only run Func1 as it is registered as an external method with EXPORT_OK, however Func2 is not. I'm guessing this means I should get some sort of error saying that Func2 is not a member of the mymodule class/module, but it doesn't, it runs it why? ...and how can I prevent it as it seems to be allowing everything into the calling script's namespace?

Regards Paul.