You mix Object Oriented Perl with Functional Perl, and you fall prey to this.
When you call a function as a method with an arrow -> , Perl passes the item on the left as the first argument to function 1 . In the case of a package name, this is simply the name of the package.
package Foo; sub frobnicate{ print "@_" } package main; Foo->frobnicate(1, 2, 3);
The result of this will be
Foo 1 2 3
So, in your case, connect_perforce will get this assignment:
my ($clientname, $p4port) = ('Perforce', 'johndoe', 'icmanage:1667' );
Thus, the variables will have the following values:
$clientname: 'Perforce' $p4port: 'johndoe'
And your string 'icmanage:1667' is lost.
If you do not have objects, do not use the arrow. The correct way to call this function (this is not a method!) Is to use the fully qualified name, including the package.
my $p4 = Perforce::connect_perforce('johndoe', $p4port);
I deleted this rather strange qw() . This will give you the literal $p4port instead of the value, so this will be another mistake you would encounter further.
Since we have established that you do not have a class, but rather a module, you also do not want to use can_ok . This is not the right test for your use case. Instead, just call the function as shown above, and then run useful tests with a return value. If the function is not there, the test program will fail, and you will notice.
BEGIN { use_ok('Perforce'); } my $p4 = Perforce::connect_perforce('johndoe', 'icmanage:1667'); isa_ok($p4, 'P4');
For more information on object orientation and modules, see perlobj and perlootut , perlnewmod, and Exporter . Perlmaven has some good articles .
1) He does more, but it is not relevant here