2a18ff4844b09cf0f5865020f7af6eac4cab82db
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / PPI.pm
1 use strict;
2 use warnings;
3 package Devel::REPL::Plugin::PPI;
4
5 use Devel::REPL::Plugin;
6 use PPI;
7 use PPI::Dumper;
8 use namespace::autoclean;
9
10 sub BEFORE_PLUGIN {
11     my $self = shift;
12     $self->load_plugin('Turtles');
13 }
14
15 sub expr_command_ppi {
16   my ( $self, $eval, $code ) = @_;
17
18   my $document = PPI::Document->new(\$code);
19   my $dumper   = PPI::Dumper->new($document);
20   return $dumper->string;
21 }
22
23 __PACKAGE__
24
25 __END__
26
27 =pod
28
29 =head1 NAME
30
31 Devel::REPL::Plugin::PPI - PPI dumping of Perl code
32
33 =head1 SYNOPSIS
34
35   repl> #ppi Devel::REPL
36   PPI::Document
37     PPI::Statement
38       PPI::Token::Word    'Devel::REPL'
39
40   repl> #ppi {
41   > warn $];
42   > }
43   PPI::Document
44     PPI::Statement::Compound
45       PPI::Structure::Block       { ... }
46         PPI::Token::Whitespace    '\n'
47         PPI::Statement
48           PPI::Token::Word        'warn'
49           PPI::Token::Whitespace          ' '
50           PPI::Token::Magic       '$]'
51           PPI::Token::Structure   ';'
52         PPI::Token::Whitespace    '\n'
53
54 =head1 DESCRIPTION
55
56 This plugin provides a C<ppi> command that uses L<PPI::Dumper> to dump
57 L<PPI>-parsed Perl documents.
58
59 The code is not actually executed, which means that when used with
60 L<Deve::REPL::Plugin::OutputCache> there is no new value in C<_>.
61
62 =head1 AUTHOR
63
64 Shawn M Moore E<lt>sartak@gmail.comE<gt>
65
66 =cut
67
68