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

Hi,

I've a small test case executor that starts external perl files given by name via
my $result = do($filename)

The test cases usually do some stuff and in error case can return at different code lines. For analysis it would be nice to see from which line the external perl file returned.

Now I could do sth. like this when returning from test case file:
return __LINE__;

But then I will need to touch all existing test cases. Any other suggestions I can solve this?

Something like caller() would be nice but it's clear contrary to a caller stack a returner stack is neither necessary nor really makes sense. But perl has such a lot special variables may be perl knows at least the last line of a "done" perl file :)

Thanks a lot for any useful comment!

Replies are listed 'Best First'.
Re: returner / opposite of caller
by LanX (Saint) on Aug 27, 2014 at 13:44 UTC
    general answer: have a look at the -D switch in perlrun , IIRC it can be used to log all call frames.

    Otherwise: it really depends on the structure of your tests, maybe it helps to have only one centralized exit point which is called via a sub xreturn() which replaces your old return .

    something like: (untested)

    my @data; sub xreturn { @data = @_; push @data, [(caller)]; goto CENTRAL_EXIT; } CENTRAL_EXIT: return @data;

    HTH! :)

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Re: returner / opposite of caller
by salva (Canon) on Aug 27, 2014 at 13:18 UTC
    Maybe the debugger could let you do that. See perldebguts and DB.
Re: returner / opposite of caller
by RonW (Parson) on Aug 27, 2014 at 16:37 UTC

    Depending on the original of these files you might want to consider using Safe