Module Testing Question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I wanted to test all the subroutines in my module from a script,
 but I have a problem. Some subroutines are called from only
inside the module and some are not. Therefore I have code

1     my ($pkg, @args) = @_
2     my @args = @_

in other places. Unfortunately if i test my sub routine that has #2 above,
I get an error because the package name is passed into the sub and the code
expecting that. Is there a way that a script can call a method in a module
and not
pass the package name?



Re: Module Testing Question

Eddie wrote:
Quoted text here. Click to load it

Of course there is.
Just leave away the OO-style "->" notation and call
your sub the "conventional" way in "::" notation.
You should propably have a look at "perldoc perloo" and
"perldoc perltoot" as well as "perldoc perlmod".

In fact, it's "->" notation that makes it possible at all
to do OO programming in Perl.

Just a little example to show the difference:

use strict;
use warnings;

package mymod;

sub displayargs {
    print "Called with:".$/;
    print "  $_".$/ for( @_ );


package main;

print "Classic notation: mymod::displayargs(...)".$/;
mymod::displayargs( 1, 2, 3 );

print $/;

print "OO notation: mymod->displayargs(...)".$/;
mymod->displayargs( 1, 2, 3 );



Re: Module Testing Question

Thanks so much. Unfortunately, I dont know the inner workings of Perl as
much as I should. I guess everyday is a learning day for me.


Quoted text here. Click to load it

Re: Module Testing Question

Quoted text here. Click to load it

Just a terminological nitpick here.  If it doesn't expect the package
(or an object) as the first parameter, it isn't a method but a plain
subroutine.  As Christian Winter has suggested in another reply, don't
call the non-methods as methods and you're set.


Site Timeline