Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Sub calling sadness

by nefigah (Monk)
on Mar 08, 2008 at 07:29 UTC ( #672948=note: print w/ replies, xml ) Need Help??


in reply to Re: Sub calling sadness
in thread Sub calling sadness

ok( ThatPackage::blah $foo, 'blah' ); means ok( ThatPackage::blah($foo, 'blah') );
Alright. Perl must fairly liberally interpret it sometimes; because it was working as ok( ThatPackage::blah($foo), 'blah' ) until $foo contained leading whitespace :( (I could tell because the ok() method was correctly printing out 'blah' as the test description)


I'm a peripheral visionary... I can see into the future, but just way off to the side.


Comment on Re^2: Sub calling sadness
Select or Download Code
Re^3: Sub calling sadness
by stiller (Friar) on Mar 08, 2008 at 07:52 UTC
    Update: I wrote the below, obviously after reading ikegami's answer above. Yet, I went on, totally wrong. The only problem with his answer was that it's a bit terse. When the sub you are calling eats the rest of the argument list, you get surprises. For example, look at print. It seems a litle silly that ok() is OK with only one argument, but it is, which hides the real problem in your code.
    sorry for confusing... (e.g.:disregard the rest of this post)

    It is not possible to explain the semantics of your code without access to the definition of ThatPackage. If you could include that definition, we could probably better explain what happens and why.

    For example, include your definition of ThatPackage::blah something like this (after verifying that it still demonstrates the problem):

    use Test::More 'no_plan'; #require 'some_file_with_my_functions.pm'; package ThatPackage; sub blah { return $_[0] =~ /hi/ }; # Does NOT demonstrate the problem package main; my $foo = "hi"; my $bar = " hi"; ok( ThatPackage::blah $foo, 'blah' ); ok( ThatPackage::blah $bar, 'blah2' ); ok( ThatPackage::blah($foo), 'blah3' ); ok( ThatPackage::blah($bar), 'blah4' );
    cheers
      Fair enough, here it all is, shortened as short as possible:

      Contents of MyFile.pm
      #!/usr/bin/env perl use warnings; use strict; use feature ':5.10'; package ThatPackage; sub parse { } # Yep, even empty the error occurs, because it never eve +n gets as far as calling it
      Contents of unit_test.pl
      #!/usr/bin/env perl -w use feature ':5.10'; use Test::More 'no_plan'; require 'MyFile.pm'; my $foo = "blah"; my $bar = " blah"; ok( ThatPackage::parse $foo, " this is a test" ); # fine, test doesn't + pass but runs fine ok( ThatPackage::parse($bar), " this is a test" ); # also fine ok( ThatPackage::parse $bar, " this is a test" ); # error here: 'Can't + call method "ThatPackage::parse" without a package or object referen +ce at unit_test.pl line 43.'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://672948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-09-20 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (163 votes), past polls