Just to keep this post from having zero value, here's another case where I used B without eval. The problem was to show what a format (set via a complex eval STRING) was getting set to. Original version only allowed deparse_format(*WHATEVER{FORMAT}) but *FOO{FORMAT} isn't supported before perl-5.7.0.
sub deparse_format { use B::Deparse; # translate arg (or reference to it) into a B::* object my $Bobj = B::svref_2object(ref $_[0] ? $_[0] : \$_[0]); # if passed a glob or globref, get the format $Bobj = B::GV::FORM($Bobj) if ref $Bobj eq 'B::GV'; if (ref $Bobj ne 'B::FM') { require Carp; Carp::croak "deparse_format: expected a glob, globref, or form +at ref"; } my $deparser = B::Deparse::->new(); return $deparser->indent($deparser->deparse_format($Bobj)); }
In reply to Re^5: Good way of handling eval failures and deparsing formats
by ysth
in thread Good way of getting subroutine name from ref?
by bronson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |