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