7
7
# This is based on the module of the same name by Malcolm Beattie,
8
8
# but essentially none of his code remains.
9
9
10
- package B::Deparse 1.87 ;
10
+ package B::Deparse 1.88 ;
11
11
use strict;
12
12
use Carp;
13
13
use B qw( class main_root main_start main_cv svref_2object opnumber perlstring
@@ -1068,6 +1068,16 @@ sub ambient_pragmas {
1068
1068
$self -> {' ambient_hinthash' } = $hinthash ;
1069
1069
}
1070
1070
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
+
1071
1081
# This method is the inner loop, so try to keep it simple
1072
1082
sub deparse {
1073
1083
my $self = shift ;
@@ -7393,7 +7403,8 @@ They exist principally so that you can write code like:
7393
7403
); }
7394
7404
7395
7405
which 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> .
7397
7408
7398
7409
=item %^H
7399
7410
@@ -7402,6 +7413,16 @@ stored in the special hash %^H.
7402
7413
7403
7414
=back
7404
7415
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
+
7405
7426
=head2 coderef2text
7406
7427
7407
7428
$body = $deparse->coderef2text(\&func)
0 commit comments