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