dly has asked for the wisdom of the Perl Monks concerning the following question:

Apologies for no real code, but the simple case does not exhibit my problem, only my real world case needing an FTP server set up exhibits the problem.

The Simple code:

# OVERRIDE_BUILD imports run_star_commands(). use App::Fetchware qw(:OVERRIDE_BUILD); run_star_commands();

seems to work just fine :(

But my complicated test environment involving a test FTP server exhibits this problem (Partial code listing):

... use Sub::Mage 'sublist'; diag("WEBAPPSLOADED!!!!!!!!!!!["); print "$_\n" for sublist(); diag("]"); use B::Deparse; my $deparse = B::Deparse->new("-p", "-sC"); my $body = $deparse->coderef2text(\&run_star_commands); diag("RUNSTARCOMMANDS["); diag("$body"); diag("]"); # Use run_start_commands from :OVERRIDE_BUILD to support uploa +d_commands # being a true ONEARRREF and having multiple commands to call. run_star_commmands(@upload_commands); } else { ...

That has the following output:

# WEBAPPSLOADED!!!!!!!!!!![ have after DATA_PROT_CONFIDENTIAL ... run_star_commands ... constructor filter splitpath CMD_OK download_dirlist # ] # RUNSTARCOMMANDS[ # { # package App::Fetchware; # use warnings; # use strict; # no feature; # use feature ':5.10'; # (my(@star_commands) = @_); # foreach my $star_command (@star_commands) { # if (($star_command =~ /,\s*/)) { # (my(@star_commands) = split(/,\s*/, $star_command, 0)); # foreach my $split_star_command (@star_commands) { # run_prog($split_star_command); # } # } else { # run_prog($star_command); # } # } # } # ] Undefined subroutine &App::FetchwareX::WebApp::run_star_commmands call +ed at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX/WebApp +.pm line 768 (#2) (F) The subroutine indicated hasn't been defined, or if it was, it + has since been undefined. Uncaught exception from user code: Undefined subroutine &App::FetchwareX::WebApp::run_star_commma +nds called at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX +/WebApp.pm line 768. at /home/dly/Desktop/Code/App-Fetchware/lib/App/FetchwareX/WebApp.pm +line 768. App::FetchwareX::WebApp::build('a') called at t/App-FetchwareX +-WebApp.t line 733 # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 25 just after 5. Dubious, test returned 25 (wstat 6400, 0x1900) Failed 1/6 subtests Test Summary Report ------------------- t/App-FetchwareX-WebApp.t (Wstat: 6400 Tests: 6 Failed: 1) Failed test: 5 Non-zero exit status: 25 Parse errors: No plan found in TAP output Files=1, Tests=6, 0 wallclock secs ( 0.03 usr 0.01 sys + 0.36 cusr + 0.12 csys = 0.52 CPU) Result: FAIL

As you can see from the output right before I call run_star_commands() I call Sub::Mage's sublist() subroutine that returns all subroutines defined in the current package. I snipped the output, but the important part is that run_star_commands() is listed.

I also use B::Deparse to deparse run_star_commands() to see if run_star_commands() can be deparsed, and it deparses it just fine.

Then the very next thing I do is call run_star_commands(), but it fails with an "Undefined subroutine" error message.

My test setup is a real disaster, so testing my code would require installing a bunch of modules, setting some crazy environment variables, and access to a FTP server. So, instead of asking you guys to git clone my repo, set insane environment variables, and setup an FTP server, what I'm looking for is a way to debug this problem myself.

Could setting a watchpoint in the debugger for run_star_commands() reveal what's making it vanish without a trace right before perl calls it? Watchpoints only seem to work for regular variables as using something like:

w $App::FetchwareX::WebApp{run_star_commands}{CODE}

causes the debugger to freak out. Is their some sort of way of accessing a subroutine "as a variable", so that I can set a watch expression on it to see where it changes?

Replies are listed 'Best First'.
Re: How can I debug a weird "Undefined subroutine..." error that should be defined.
by Corion (Patriarch) on Mar 01, 2015 at 09:01 UTC

    Please read your code closer. Perl and all the diagnostics are correct, but if you're not reading them closely, they won't help.

    run_star_commands run_star_commmands

      You're totally right! That bug's fixed. I even copied and pasted :OVERRIDE_BUILD a couple of times to avoid this problem, which I've even run into before, but never the name of the subroutine. Now I wish I had.

      This isn't even the first time I've done this. I once submitted a bug report where perl was messing with one of my variables, but the problem turned out to be caused by a bug in my test case. That one lives on in infamy in perl's bug queue somewhere with all the other bugs that aren't actually bugs.

      It's so easy to get frustrated, and fixating on something that's not actually the problem. Oops...I'll keep this in mind the next time I think perl is wrong and I am right.

      That being said Sometimes, it really IS a bug in Perl; however, the bug in question is on a totally different level than my typo of a bug.

      Thanks for reading my code more carefully than I was.

Re: How can I debug a weird "Undefined subroutine..." error that should be defined.
by Mr. Muskrat (Canon) on Mar 03, 2015 at 18:02 UTC

    Are you sure that you are calling run_star_commands correctly in App::FetchwareX::WebApp or that it has been imported properly to that namespace? If I am reading the above output correctly, it appears to exist in App::Fetchware.

    It's really hard to tell what is what based solely on what you have told us.

      Hang on a second... Is it possible that a call to App::FetchwareX::WebApp::run_star_commmands got inserted into @upload_commands?