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