Refactor to make it easier to add print/warn to the session
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / B / Concise.pm
CommitLineData
320b3ad5 1#!/usr/bin/perl
2
3package Devel::REPL::Plugin::B::Concise;
4use Devel::REPL::Plugin;
5
6use B::Concise ();
7
8B::Concise::compileOpts(qw(-nobanner));
9
10use namespace::clean -except => [ 'meta' ];
11
12with qw(Devel::REPL::Plugin::Turtles);
13
14sub 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
26sub 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
3d22167c 33 if ( $self->is_error($sub) ) {
34 return $self->format($sub);
35 } else {
36 open my $fh, ">", \my $out;
37 {
38 local *STDOUT = $fh;
39 B::Concise::compile((split /\s+/, $opts), $sub)->();
40 }
41
42 return $out;
320b3ad5 43 }
320b3ad5 44}
45
46__PACKAGE__
47
48__END__
49
50=pod
51
52=head1 NAME
53
54Devel::REPL::Plugin::B::Concise - B::Concise dumping of expression optrees
55
56=head1 SYNOPSIS
57
58 repl> #concise -exec -terse {
59 > foo => foo(),
60 > }
61 COP (0x138b1e0) nextstate
62 OP (0x13bd280) pushmark
63 SVOP (0x138c6a0) const PV (0xbbab50) "foo"
64 OP (0x13bbae0) pushmark
65 SVOP (0x13bcee0) gv GV (0xbbb250) *Devel::REPL::Plugin::B::Concise::foo
66 UNOP (0x13890a0) entersub [1]
67 LISTOP (0x13ba020) anonhash
68 UNOP (0x5983d0) leavesub [1]
69
70=head1 DESCRIPTION
71
72This plugin provides a C<concise> command that uses L<B::Concise> to dump
73optrees of expressions.
74
75The code is not actually executed, which means that when used with
76L<Deve::REPL::Plugin::OutputCache> there is .
77
78The command takes the same options as L<B::Concise/compile>, e.g. C<-basic> or
79C<-exec> to determine the dump order, C<-debug>, C<-concise> and C<-terse> to
80determine the formatting, etc.
81
82=head1 AUTHOR
83
84Yuval Kogman E<lt>nothingmuch@woobling.orgE<gt>
85
86=cut
87
88