http://qs1969.pair.com?node_id=323992

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

Hi.

Mason scoping question. Here's a reduction that illustrates the issue:

Why does this work properly (that is, the error message is sent off to the component)

<html> <body> % eval { die "this is an error"; }; % if ($@) { % my $message = $@; % $m->comp('/comps/error.comp', message=> $message); % } </body> </html>
But this does not work properly (a blank string is sent off the component)
<html> <body> % eval { die "this is an error"; }; % if ($@) { % $m->comp('/comps/error.comp', message=> $@); % } </body> </html>
Thanks for any insight.

rkg

UPDATE

Ok, since (notice the quotes)

$m->comp('/comps/error.comp', message=> "$@");
does work properly, I'm wondering if the issue is Mason, or if $@ has magic properties...

is $@ a simple scalar, or something more?

Replies are listed 'Best First'.
Re: Mason and $@
by Fletch (Bishop) on Jan 25, 2004 at 19:13 UTC

    $@ can be changed by any intermediate steps which happen to cause it to change. I can't think it's out of the question that some part of the component resolution code is using an eval which is succeeding and thus clearing it out. Like $1 or $!, unless you can absolutely count on other code not doing something to change it your best bet's copying it (either explicitly or through stringifying it).

Re: Mason and $@
by coec (Chaplain) on Jan 25, 2004 at 20:39 UTC
    A stab in the dark here, but it would be useful to see what $@ contains. I'm thinking that it would be expected to get an error if $@ contains one or more spaces. Maybe a
    print Data::Dumper $@
    or similar?