Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Debugging failed "use" statement.

by cLive ;-) (Prior)
on May 06, 2007 at 01:08 UTC ( [id://613775]=perlquestion: print w/replies, xml ) Need Help??

cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

This one's driving me crazy. I appear to be going round in circles, so I'd value any input. So far I've narrowed it down to this.

#> perl -c Some/Module.pm Some/Module.pm syntax OK #> perl -MSome::Module Some/Module.pm did not return a true value.

Yes, the module ends with a 1;

Why would this pass a -c check, yet fail when required? What am I missing? I have a feeling I've hit this one before in the past, but I can't remember for sure. Grrrr.

EDIT: I was being braindead - I have hit this problem before...

Replies are listed 'Best First'.
Re: Debugging failed "use" statement.
by merlyn (Sage) on May 06, 2007 at 01:25 UTC
Re: Debugging failed "use" statement.
by chromatic (Archbishop) on May 06, 2007 at 04:45 UTC

    Perl doesn't know that Some/Module.pm is a module when you load it with -c. All it knows is that you've given it a filename--and that filename can be anything and have any extension that your particular operating system and filesystem allow.

    Just as a .pl file doesn't have to end by returning a true value, neither does a module until you tell Perl to treat it as a module. The -M flag does that, just as do use and require.

    Edit: removed a sentence.

Re: Debugging failed "use" statement.
by naikonta (Curate) on May 06, 2007 at 01:28 UTC
    Hi cLive;-), I believe you already know that the perl -c checks the syntax and catches compile time error such as undeclare variables under strict or missing brackets or semicolon when it's due. As long as the code succeeds to compile, then the syntax is fine. But, this tells nothing about runtime execution. Checking true value of module is done at runtime which happens when the module is require'd or use'd.

    However, as you're confident the module ends with 1; I think you need to show your code, specially perhaps the last lines. It seems that perl is as confident as you are in that it doesn't see the true value as the last statement when running the module.


    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: Debugging failed "use" statement. (guess)
by tye (Sage) on May 06, 2007 at 01:30 UTC

    Perhaps any of several reasons, I'd think. One simple reason that occurs to me is:

    ... return 0; ... 1;

    Why do you think we would be better at deducing the answer when you deny us nearly all concrete information about the problem?

    You could try "perl -MO=Deparse Some/Module.pm" to see if the problem has been obscured by syntax. You could try "perl -del" then "s require Some::Module" then "n" until failure.

    - tye        

Re: Debugging failed "use" statement.
by Cody Pendant (Prior) on May 06, 2007 at 04:20 UTC
    Just for the record, I want to say that the module you're using when you do
    #> perl -c Some/Module.pm
    could be a completely different module from the one you get when you do
    #> perl -MSome::Module
    depending on your @INC.


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re: Debugging failed "use" statement.
by liverpole (Monsignor) on May 06, 2007 at 01:37 UTC
    Hi cLive ;-),

    It's an interesting problem for sure.

    What if you were to sprinkle deliberate syntax errors throughout your code?  For example, if you put ;+++; on the last line prior to the final 1; like so:

    # Intentional error ;+++; 1;

    Does that give you a syntax error with perl -c?

    And if it doesn't, try sprinkling the same error (or one of your choice) throughout your code until you find the first place where it does cause an error ... then see what's between that line and the next one where the error should have occurred.

    For example, it might turn out to be similar to ...

    # This line causes an error ;+++; # ... print "Another section\n"; __END__ # ... # Thought this would error, but doesn't ;+++; print "Final section\n"; 1;

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: Debugging failed "use" statement.
by cLive ;-) (Prior) on May 06, 2007 at 01:42 UTC

    Yes I'm sure there's no __END__ or exit(0); statements.

    Sorry I can't post the code. I'm not allowed to.

    One thing I have found is that if I remove a particular method, I don't get the error. However, on going through that method line by line, the error drops on removal of 5 lines of commented code. That seems really bizarre.

    I have a feeling it's POD related, but the module passes POD::Checker just fine.

    Maybe if I strip all the POD out and then see if it works I'll get more info. 'tis a strange one for not throwing an error, I must say.

    D'OH. Forget it. It was a legacy module with the damn use Switch statement in it. Heh - that was my last question 2 months ago. Damn memory... serves me right for merging back into the trunk on an empty head :)

    Thanks all for the quick replies - I have a feeling my evening will flow a lot better now :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://613775]
Approved by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found