—#!/usr/bin/env perl
use
strict;
use
warnings;
use
PPI::Document;
use
PPI::Dumper;
my
$whitespace
=
$ARGV
[0] &&
$ARGV
[0] eq
'-w'
?
shift
: 0;
my
$code
=
$ARGV
[0] ? (-f
$ARGV
[0] ?
shift
: \
shift
) : \
join
q{}
, <STDIN>;
my
$doc
= PPI::Document->new(
$code
)
or
die
'Could not parse code: '
, PPI::Document::errstr(),
"\n"
;
my
$dump
= PPI::Dumper->new(
$doc
,
whitespace
=>
$whitespace
,
locations
=> 1 );
$dump
->
();
__END__
#-----------------------------------------------------------------------------
=pod
=head1 NAME
ppidump - Dump Perl code as PPI structure.
=head1 SYNOPSIS
ppidump #Read from STDIN
ppidump MyModule.pm #Read code from file
ppidump 'my $foo = $bar;' #Read code as from string
ppidump -w 'foo( );' #Show whitespace tokens
=head1 DESCRIPTION
This is a simple tool for helping to develop Perl::Critic::Policy
modules. If you want to see how L<PPI|PPI> would parse a snippet of
code, just feed it to C<ppidump>.
By default, whitespace tokens are hidden. Use the C<-w> flag to show
them.
=head1 AUTHOR
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
=head1 COPYRIGHT
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
=cut
##############################################################################
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# indent-tabs-mode: nil
# c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :