in reply to Re: How to tell eval where the code is from
in thread How to tell eval where the code is from

Thank you very much for your help.

I am still stuck with AUTOLOADed routines: When the routine is called the first time, AUTOLOAD executes a statement like

$code=$database{$AUTOLOAD}; # e.g: "sub pkg::foo {...}" eval $code; $@ and error_msg($AUTOLOAD, $@, $code); goto &$AUTOLOAD;

This code catches compilation errors. But when the routine is actually called later, the variable $@ is no longer active.

Also, warnings (like those for undefined values) are generated without giving the running code an opportunity to add some information.

Replies are listed 'Best First'.
RE: RE: Re: How to tell eval where the code is from
by merlyn (Sage) on Aug 08, 2000 at 16:35 UTC
    Inside your eval, add something like:
    $code = $database{$AUTOLOAD}; $pseudo_file = get_pseudo_for($AUTOLOAD); # like "Database_entry_for_p +kg::foo" eval qq{#line 1 "$pseudo_file"\n$code}; ...
    Now when an error triggers, you'll get
    whatever error from Database_entry_for_pkg::foo, line 14
    in $@ Use the cpp triggers, luke!

    -- Randal L. Schwartz, Perl hacker

      Thank you very much. This solves my problem.

      I would much appreciate a source reference where I could have found that information myself. I bet I find other interesting things there, too.

      Yaakov

RE: RE: Re: How to tell eval where the code is from
by tilly (Archbishop) on Aug 08, 2000 at 16:14 UTC
    I thought of this after I posted.

    I actually think that your original approach is the right idea, wrong syntax. A better approach probably would be to provide a second optional argument to eval() that is the name to call this error.

    In any case I suggest that you sign up for the perl5-porters list, state your problem, state your proposed solution, and see if you cannot get it accepted. Possibly with the syntax I am recommending. Possibly with some better syntax that they think of.

        Live and learn!

        Is this documented anywhere? Other than in your brain and the code?