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