[tpm] Perl module question

Madison Kelly linux at alteeve.com
Fri Sep 7 09:20:29 PDT 2007


Hi all,

   I am quite the module n00b, so please be gentle. :)

   I've got a few small, simple modules I've written that handle some 
simple functions I use often. What I want to be able to do though is:

my $foo=My::Module->new();

   Then be able to call the function/subroutines in there like this:

my $value=$foo->function($var1, $var2);

   I had tried to do:

my $value=My::Module->function($var1, $var2);

   But the first value picked up in the function is the module name... I 
don't think I should have to say in the module

sub function
{
	my ($null, $var1, $var2)=@_;
	...
}

   In order to do this. I don't like just calling the function name (as 
I currently do) because some of the funtion names are ambiguous. For 
example, one module is used to validate form values. So the function 
'phone', 'int_num', 'real_num' and so on are provided by 'NV::Validate'. 
If I want to validate the phone number then, I'd call:

my ($valid)=phone($form_phone_num);

   This is fairly ambiguous, and I'd much rather say either:

my $validate=NV::Validate->new();
my ($value)=$validate->phone($form_phone_num);

   Or

my ($value)=NV::Validate->phone($form_phone_num);

   But not have the first variable passed being the module name.

Any tips, pointers or such? Would it help to show some code samples from 
my module?

   Thanks!

Madison


More information about the toronto-pm mailing list