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