add use strict; use warnings to modules, just to be sure
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / B / Concise.pm
CommitLineData
320b3ad5 1#!/usr/bin/perl
2
1716b200 3use strict;
4use warnings;
320b3ad5 5package Devel::REPL::Plugin::B::Concise;
6use Devel::REPL::Plugin;
7
8use B::Concise ();
9
10B::Concise::compileOpts(qw(-nobanner));
11
aa8b7647 12use namespace::autoclean;
320b3ad5 13
3a400715 14sub BEFORE_PLUGIN {
15 my $self = shift;
16 $self->load_plugin('Turtles');
17}
320b3ad5 18
19sub AFTER_PLUGIN {
20 my $self = shift;
21
22 my $prefix = $self->default_command_prefix;
23
24 $self->add_turtles_matcher(qr/^
25 \#(concise) \s+
26 ( (?:\-\w+\s+)* ) # options for concise
27 (.*) # the code
28 /x);
29}
30
31sub expr_command_concise {
32 my ( $self, $eval, $opts, $code ) = @_;
33
34 die unless $code;
35
9c3c6bc8 36 my %opts = map { $_ => 1 } (split /\s+/, $opts);
37
38 my $sub = $self->compile($code, no_mangling => !delete($opts{"-mangle"}) );
320b3ad5 39
3d22167c 40 if ( $self->is_error($sub) ) {
41 return $self->format($sub);
42 } else {
43 open my $fh, ">", \my $out;
44 {
45 local *STDOUT = $fh;
9c3c6bc8 46 B::Concise::compile(keys %opts, $sub)->();
3d22167c 47 }
48
49 return $out;
320b3ad5 50 }
320b3ad5 51}
52
53__PACKAGE__
54
55__END__
56
57=pod
58
59=head1 NAME
60
61Devel::REPL::Plugin::B::Concise - B::Concise dumping of expression optrees
62
63=head1 SYNOPSIS
64
65 repl> #concise -exec -terse {
66 > foo => foo(),
67 > }
68 COP (0x138b1e0) nextstate
69 OP (0x13bd280) pushmark
70 SVOP (0x138c6a0) const PV (0xbbab50) "foo"
71 OP (0x13bbae0) pushmark
72 SVOP (0x13bcee0) gv GV (0xbbb250) *Devel::REPL::Plugin::B::Concise::foo
73 UNOP (0x13890a0) entersub [1]
74 LISTOP (0x13ba020) anonhash
75 UNOP (0x5983d0) leavesub [1]
76
77=head1 DESCRIPTION
78
79This plugin provides a C<concise> command that uses L<B::Concise> to dump
80optrees of expressions.
81
82The code is not actually executed, which means that when used with
c5bf3ed2 83L<Deve::REPL::Plugin::OutputCache> there is no new value in C<_>.
320b3ad5 84
85The command takes the same options as L<B::Concise/compile>, e.g. C<-basic> or
86C<-exec> to determine the dump order, C<-debug>, C<-concise> and C<-terse> to
87determine the formatting, etc.
88
89=head1 AUTHOR
90
91Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
92
93=cut
94
95