This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Bump versions of modules that are currently on "dev" releases in maint.
[perl5.git] / ext / B / B / Terse.pm
CommitLineData
a798dbf2 1package B::Terse;
28b605d8 2
828888e0 3our $VERSION = '1.04';
28b605d8 4
ad4997d3 5use strict;
31b49ad4 6use B qw(class);
ad4997d3 7use B::Asmdata qw(@specialsv_name);
8ec8fbef 8use B::Concise qw(concise_subref set_style_standard);
31b49ad4 9use Carp;
ad4997d3
JH
10
11sub terse {
8ec8fbef 12 my ($order, $subref) = @_;
31b49ad4 13 set_style_standard("terse");
ad4997d3 14 if ($order eq "exec") {
8ec8fbef 15 concise_subref('exec', $subref);
ad4997d3 16 } else {
8ec8fbef 17 concise_subref('basic', $subref);
ad4997d3
JH
18 }
19}
a798dbf2
MB
20
21sub compile {
31b49ad4
SM
22 my @args = @_;
23 my $order = @args ? shift(@args) : "";
24 $order = "-exec" if $order eq "exec";
25 unshift @args, $order if $order ne "";
26 B::Concise::compile("-terse", @args);
ad4997d3
JH
27}
28
29sub indent {
cc02ea56 30 my ($level) = @_ ? shift : 0;
ad4997d3
JH
31 return " " x $level;
32}
33
31b49ad4
SM
34# Don't use this, at least on OPs in subroutines: it has no way of
35# getting to the pad, and will give wrong answers or crash.
ad4997d3 36sub B::OP::terse {
31b49ad4
SM
37 carp "B::OP::terse is deprecated; use B::Concise instead";
38 B::Concise::b_terse(@_);
ad4997d3
JH
39}
40
31b49ad4
SM
41sub B::SV::terse {
42 my($sv, $level) = (@_, 0);
43 my %info;
44 B::Concise::concise_sv($sv, \%info);
cc02ea56
JC
45 my $s = indent($level)
46 . B::Concise::fmt_line(\%info, $sv,
47 "#svclass~(?((#svaddr))?)~#svval", 0);
48 chomp $s;
49 print "$s\n" unless defined wantarray;
50 $s;
d333a217
RGS
51}
52
ad4997d3 53sub B::NULL::terse {
5638aaac 54 my ($sv, $level) = (@_, 0);
cc02ea56
JC
55 my $s = indent($level) . sprintf "%s (0x%lx)", class($sv), $$sv;
56 print "$s\n" unless defined wantarray;
57 $s;
ad4997d3 58}
31b49ad4 59
ad4997d3 60sub B::SPECIAL::terse {
5638aaac 61 my ($sv, $level) = (@_, 0);
cc02ea56
JC
62 my $s = indent($level)
63 . sprintf( "%s #%d %s", class($sv), $$sv, $specialsv_name[$$sv]);
64 print "$s\n" unless defined wantarray;
65 $s;
a798dbf2
MB
66}
67
681;
7f20e9dd
GS
69
70__END__
71
72=head1 NAME
73
74B::Terse - Walk Perl syntax tree, printing terse info about ops
75
76=head1 SYNOPSIS
77
ad4997d3 78 perl -MO=Terse[,OPTIONS] foo.pl
7f20e9dd
GS
79
80=head1 DESCRIPTION
81
31b49ad4
SM
82This version of B::Terse is really just a wrapper that calls B::Concise
83with the B<-terse> option. It is provided for compatibility with old scripts
84(and habits) but using B::Concise directly is now recommended instead.
85
3c4b39be 86For compatibility with the old B::Terse, this module also adds a
31b49ad4
SM
87method named C<terse> to B::OP and B::SV objects. The B::SV method is
88largely compatible with the old one, though authors of new software
89might be advised to choose a more user-friendly output format. The
90B::OP C<terse> method, however, doesn't work well. Since B::Terse was
91first written, much more information in OPs has migrated to the
92scratchpad datastructure, but the C<terse> interface doesn't have any
93way of getting to the correct pad. As a kludge, the new version will
94always use the pad for the main program, but for OPs in subroutines
95this will give the wrong answer or crash.
7f20e9dd
GS
96
97=head1 AUTHOR
98
31b49ad4
SM
99The original version of B::Terse was written by Malcolm Beattie,
100E<lt>mbeattie@sable.ox.ac.ukE<gt>. This wrapper was written by Stephen
101McCamant, E<lt>smcc@MIT.EDUE<gt>.
7f20e9dd
GS
102
103=cut