Subject: | can breaks exceptions, like $@->can |
Below a two perl snippets, equal to each other, except for the usage of UNIVERSAL::isa. They are all valid method calls of can. however with UNIVERSAL::isa the calll dies.
perl -wle 'use strict; eval { die bless {}, "main" }; print $@->can("x")'
perl -wle 'use UNIVERSAL::can; use strict; eval { die bless {}, "main" }; print $@->can("x")'
and a workaround:
perl -wle 'use UNIVERSAL::can; use strict; eval { die bless {}, "main" }; my $a=$@; print $a->can("x")'
Enviroment is freebsd, and perl 5.8.7
This is due to UNIVERSAL::can does not make a copy of $_[0], but works on the callers copy. In this case $@. Then can calls eval itself, $@ will be empty, and so will $_[0].
Solution:
Either make a copy of $@. Or try to do a "local $@" before the eval?