xref: /openbsd/gnu/usr.bin/perl/ext/B/B/Terse.pm (revision f3efcd01)
1package B::Terse;
2
3our $VERSION = '1.09';
4
5use strict;
6use B qw(class @specialsv_name);
7use B::Concise qw(concise_subref set_style_standard);
8use Carp;
9
10sub terse {
11    my ($order, $subref) = @_;
12    set_style_standard("terse");
13    if ($order eq "exec") {
14	concise_subref('exec', $subref);
15    } else {
16	concise_subref('basic', $subref);
17    }
18}
19
20sub compile {
21    my @args = @_;
22    my $order = @args ? shift(@args) : "";
23    $order = "-exec" if $order eq "exec";
24    unshift @args, $order if $order ne "";
25    B::Concise::compile("-terse", @args);
26}
27
28sub indent {
29    my ($level) = @_ ? shift : 0;
30    return "    " x $level;
31}
32
33
34sub B::SV::terse {
35    my($sv, $level) = (@_, 0);
36    my %info;
37    B::Concise::concise_sv($sv, \%info);
38    my $s = indent($level)
39	. B::Concise::fmt_line(\%info, $sv,
40				 "#svclass~(?((#svaddr))?)~#svval", 0);
41    chomp $s;
42    print "$s\n" unless defined wantarray;
43    $s;
44}
45
46sub B::NULL::terse {
47    my ($sv, $level) = (@_, 0);
48    my $s = indent($level) . sprintf "%s (0x%lx)", class($sv), $$sv;
49    print "$s\n" unless defined wantarray;
50    $s;
51}
52
53sub B::SPECIAL::terse {
54    my ($sv, $level) = (@_, 0);
55    my $s = indent($level)
56	. sprintf( "%s #%d %s", class($sv), $$sv, $specialsv_name[$$sv]);
57    print "$s\n" unless defined wantarray;
58    $s;
59}
60
611;
62
63__END__
64
65=head1 NAME
66
67B::Terse - Walk Perl syntax tree, printing terse info about ops
68
69=head1 SYNOPSIS
70
71	perl -MO=Terse[,OPTIONS] foo.pl
72
73=head1 DESCRIPTION
74
75This module prints the contents of the parse tree, but without as much
76information as CPAN module B::Debug.  For comparison, C<print "Hello, world.">
77produced 96 lines of output from B::Debug, but only 6 from B::Terse.
78
79This module is useful for people who are writing their own back end,
80or who are learning about the Perl internals.  It's not useful to the
81average programmer.
82
83This version of B::Terse is really just a wrapper that calls L<B::Concise>
84with the B<-terse> option. It is provided for compatibility with old scripts
85(and habits) but using B::Concise directly is now recommended instead.
86
87For compatibility with the old B::Terse, this module also adds a
88method named C<terse> to B::OP and B::SV objects. The B::SV method is
89largely compatible with the old one, though authors of new software
90might be advised to choose a more user-friendly output format. The
91B::OP C<terse> method, however, doesn't work well. Since B::Terse was
92first written, much more information in OPs has migrated to the
93scratchpad datastructure, but the C<terse> interface doesn't have any
94way of getting to the correct pad. As a kludge, the new version will
95always use the pad for the main program, but for OPs in subroutines
96this will give the wrong answer or crash.
97
98=head1 AUTHOR
99
100The original version of B::Terse was written by Malcolm Beattie,
101E<lt>mbeattie@sable.ox.ac.ukE<gt>. This wrapper was written by Stephen
102McCamant, E<lt>smcc@MIT.EDUE<gt>.
103
104=cut
105