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

Re: CGI::Appl can't find sub

by jimt999 (Initiate)
on Jun 13, 2014 at 21:41 UTC ( [id://1089851]=note: print w/replies, xml ) Need Help??


in reply to CGI::Appl can't find sub

I have determined the cause of the problem. Here are more details to the calls made for the problem seen when adding a new call in AA.pm to BB.pm.
AA.pm use strict use warning sub Abug1 {} sub Asub2 { BB::Bsub1(1,2,3); BB::Bsub2(hostname); # hostname is a "bareword" } sub Asub3 {}

Asub2() is only invoked at runtime via CGI::Applicaton run_modes(). The problem is that with "strict" enabled, barewords are not allowed as parameters to subroutine calls. Instead of reporting an error, the compilation is quietly aborted in the *next* subroutine when a single quote is found: resulting in all subsequent subroutines not being compiled. It also results in the program running for code that compiled and the offending subroutine working just fine. I could see that the other subroutines were missing in the debugger, I just couldn't figure out why. The key was running:

perl -MO=Terse AA.pm

It reports the offending line and where compilation is terminated. I'm glad I ignored the module description I found on perl.org:

"This module is useful for people who are writing their own back end, or who are learning about the Perl internals. It's not useful to the average programmer."

I expect that this is an unusual case because:

1. The resolution of the function doesn't occur until the specific web page is selected and is done as a string lookup.

2. The invocation of the subroutine is protected in "eval { }" so the program keeps on running.

Thanks for the input and I hope this can help someone in the future.

Replies are listed 'Best First'.
Re^2: CGI::Appl can't find sub
by Anonymous Monk on Jun 14, 2014 at 01:05 UTC

    The problem is that with "strict" enabled, barewords are not allowed as parameters to subroutine calls Instead of reporting an error, the compilation is quietly aborted in the *next* subroutine when a single quote is found

    barewords don't have that effect, they're not magic

      Okay, then please explain the output from the "perl -MO=Terse AA.pm", which is:

      Bareword "CA_list" not allowed while "strict subs" in use at AA.pm line 309. BEGIN not safe after errors--compilation aborted at AA.pm line 423.

      Note that line 423 is about 15 lines into the *next* subroutine after the one with the bareword parameter. Adding double quotes to the parameter fixed the problem. What made this so hard to root cause is that the problem did not cause the subroutine with the problem to fail. The error message also corresponds with what was observable in the perl debugger - "S AA" failed to show any subroutines after the one that contained line #309.

        Okay, then please explain the output from the "perl -MO=Terse AA.pm", which is ...

        Ask yourself , why am I using barewords?

        If they're not function/package names, or hash keys, then they shouldn't be barewords

        If your barewords are strings, you should quote your strings

        perlintro, Basic debugging checklist and brian's Guide to Solving Any Perl Problem

        If this code you posted in Re: CGI::Appl can't find sub is any indication it means perintro was skipped

        $ perl -c aa.pm syntax error at aa.pm line 4, near "use strict use warning " syntax error at aa.pm line 8, near "}" aa.pm had compilation errors.

        Tracking down syntax errors is very easy, its

        perl -c everyfile.pl perl -c lib/Everyfile.pm ...

        When you're developing , skip B::Terse, don't forget to test every single subroutine in you write in your test suite, so even if eval is hiding any die-ing you'll notice when you typo

        Hi :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-05-26 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found