77# This is based on the module of the same name by Malcolm Beattie,
88# but essentially none of his code remains.
99
10- package B::Deparse 1.87 ;
10+ package B::Deparse 1.88 ;
1111use strict;
1212use Carp;
1313use B qw( class main_root main_start main_cv svref_2object opnumber perlstring
@@ -1068,6 +1068,16 @@ sub ambient_pragmas {
10681068 $self -> {' ambient_hinthash' } = $hinthash ;
10691069}
10701070
1071+ sub ambient_pragmas_from_caller {
1072+ my $self = shift ;
1073+ my ($hint_bits , $warning_bits , $hinthash ) = (caller (0))[8, 9, 10];
1074+ $self -> ambient_pragmas(
1075+ hint_bits => $hint_bits ,
1076+ warning_bits => $warning_bits ,
1077+ ' %^H' => $hinthash ,
1078+ );
1079+ }
1080+
10711081# This method is the inner loop, so try to keep it simple
10721082sub deparse {
10731083 my $self = shift ;
@@ -7393,7 +7403,8 @@ They exist principally so that you can write code like:
73937403 ); }
73947404
73957405which specifies that the ambient pragmas are exactly those which
7396- are in scope at the point of calling.
7406+ are in scope at the point of calling. However, see also
7407+ L</ambient_pragmas_from_caller> .
73977408
73987409=item %^H
73997410
@@ -7402,6 +7413,16 @@ stored in the special hash %^H.
74027413
74037414=back
74047415
7416+ =head2 ambient_pragmas_from_caller
7417+
7418+ $deparse->ambient_pragmas_from_caller()
7419+
7420+ A convenient shortcut for setting the hints and warnings ambient pragmas to
7421+ those of the immediately calling code. This uses the
7422+ L<caller|perlfunc/caller> function to determine the hints and warnings bits in
7423+ effect at the callsite to this method, and sets those as the ambient settings
7424+ for the deparser.
7425+
74057426=head2 coderef2text
74067427
74077428 $body = $deparse->coderef2text(\&func)
0 commit comments