| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::PPI::Dumper; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = "1.022"; | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | =encoding utf8 | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | App::PPI::Dumper - Use the PPI to dump the structure of a Perl file | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | use App::PPI::Dumper; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | App::PPI::Dumper->run( @ARGV ); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | Parse a Perl document with PPI and dump the Perl Document Object Model (PDOM). | 
| 20 |  |  |  |  |  |  | This script is a command-line interface to PPI::Dumper. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head2 Methods | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =over 4 | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =item run( OPTIONS, INPUT_FILE ) | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | Parse INPUT_FILE with the given PPI::Dumper options, then print the result to | 
| 29 |  |  |  |  |  |  | standard output. | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | =over 4 | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | =item -m | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | Show the memory address of each PDOM element. | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =item -i N | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | Ident each level of output by N spaces. The default is 2. | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | =item -P | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | Do not show the full package name for each PPI class. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | =item -T | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | Do not show the original source token that goes with each PPI object. | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =item -W | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | Do not show whitespace tokens. | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =item -C | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | Do not show comment tokens. | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =item -l | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | Show the source code location of each PPI token. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =item -r | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | Parse the input in readonly mode. See PPI::Document::new() for the details. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =back | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =back | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | Most behaviour, including environment variables and configuration, | 
| 72 |  |  |  |  |  |  | comes directly from PPI::Dumper. I just made a command-line tool for it. | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 SOURCE AVAILABILITY | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | This code is in Github: | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | git://github.com/briandfoy/app-ppi-dumper.git | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =head1 AUTHOR | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | brian d foy, C<<  >> | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | Copyright © 2009-2021, brian d foy . All rights reserved. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | You may redistribute this under the terms of the Artistic License 2.0. | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =cut | 
| 91 |  |  |  |  |  |  |  | 
| 92 | 2 |  |  | 2 |  | 5935 | use Getopt::Std qw(getopts); | 
|  | 2 |  |  |  |  | 111 |  | 
|  | 2 |  |  |  |  | 118 |  | 
| 93 | 2 |  |  | 2 |  | 1072 | use PPI; | 
|  | 2 |  |  |  |  | 225159 |  | 
|  | 2 |  |  |  |  | 267 |  | 
| 94 | 2 |  |  | 2 |  | 1022 | use PPI::Dumper; | 
|  | 2 |  |  |  |  | 1943 |  | 
|  | 2 |  |  |  |  | 456 |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | __PACKAGE__->run(@ARGV) unless caller; | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | # same defaults as PPI::Dumper | 
| 99 |  |  |  |  |  |  | sub run { | 
| 100 | 8 |  |  | 8 | 1 | 22385 | my $self = shift; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 8 |  |  |  |  | 26 | local @ARGV = @_; | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 8 |  |  |  |  | 42 | my %opts = ( | 
| 105 |  |  |  |  |  |  | 'm' => 0, # memaddr | 
| 106 |  |  |  |  |  |  | 'i' => 2, # indent | 
| 107 |  |  |  |  |  |  | 'P' => 0, # class | 
| 108 |  |  |  |  |  |  | 'D' => 0, # content | 
| 109 |  |  |  |  |  |  | 'W' => 0, # whitespace | 
| 110 |  |  |  |  |  |  | 'C' => 0, # comments | 
| 111 |  |  |  |  |  |  | 'l' => 0, # locations | 
| 112 |  |  |  |  |  |  | 'r' => 0, # read-only, for PPI::Document | 
| 113 |  |  |  |  |  |  | ); | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 8 |  |  |  |  | 32 | getopts('mPDWCli:', \%opts); | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | my $Module = PPI::Document->new( | 
| 118 |  |  |  |  |  |  | $ARGV[0], | 
| 119 | 8 |  |  |  |  | 403 | readonly => $opts{'r'}, | 
| 120 |  |  |  |  |  |  | ); | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 8 | 50 |  |  |  | 10398 | die "Could not parse [$ARGV[0]] for PPI: " . PPI::Document->errstr . "\n" | 
| 123 |  |  |  |  |  |  | if PPI::Document->errstr; | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | my $Dumper = PPI::Dumper->new( $Module, | 
| 126 |  |  |  |  |  |  | memaddr    =>   $opts{'m'}, | 
| 127 |  |  |  |  |  |  | indent     =>   $opts{'i'}, | 
| 128 |  |  |  |  |  |  | class      => ! $opts{'P'}, | 
| 129 |  |  |  |  |  |  | content    => ! $opts{'D'}, | 
| 130 |  |  |  |  |  |  | whitespace => ! $opts{'W'}, | 
| 131 |  |  |  |  |  |  | comments   => ! $opts{'C'}, | 
| 132 | 8 |  |  |  |  | 72 | locations  =>   $opts{'l'}, | 
| 133 |  |  |  |  |  |  | ); | 
| 134 |  |  |  |  |  |  |  | 
| 135 | 8 |  |  |  |  | 992 | $Dumper->print; | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | 1; | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | __END__ |