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