Devel::REPL::Plugin::PPI - PPI dumping of Perl code


Devel-REPL documentation Contained in the Devel-REPL distribution.

Index


Code Index:

NAME

Top

Devel::REPL::Plugin::PPI - PPI dumping of Perl code

SYNOPSIS

Top

  repl> #ppi Devel::REPL
  PPI::Document
    PPI::Statement
      PPI::Token::Word    'Devel::REPL'

  repl> #ppi {
  > warn $];
  > }
  PPI::Document
    PPI::Statement::Compound
      PPI::Structure::Block       { ... }
        PPI::Token::Whitespace    '\n'
        PPI::Statement
          PPI::Token::Word        'warn'
          PPI::Token::Whitespace          ' '
          PPI::Token::Magic       '$]'
          PPI::Token::Structure   ';'
        PPI::Token::Whitespace    '\n'

DESCRIPTION

Top

This plugin provides a ppi command that uses PPI::Dumper to dump PPI-parsed Perl documents.

The code is not actually executed, which means that when used with Deve::REPL::Plugin::OutputCache there is no new value in _.

AUTHOR

Top

Shawn M Moore <sartak@gmail.com>


Devel-REPL documentation Contained in the Devel-REPL distribution.

#!/usr/bin/perl

package Devel::REPL::Plugin::PPI;
use Devel::REPL::Plugin;

use PPI;
use PPI::Dumper;

use namespace::clean -except => [ 'meta' ];

sub BEFORE_PLUGIN {
    my $self = shift;
    $self->load_plugin('Turtles');
}

sub expr_command_ppi {
  my ( $self, $eval, $code ) = @_;

  my $document = PPI::Document->new(\$code);
  my $dumper   = PPI::Dumper->new($document);
  return $dumper->string;
}

__PACKAGE__

__END__