Debian Codegraph @

eg/pqldump

raw
1 #!/usr/bin/env perl
2
3 use 5.006;
4
5 use strict;
6 use warnings;
7
8 use Getopt::Long 2.33 qw{ :config auto_version };
9 use Pod::Usage;
10 use PPIx::QuoteLike::Dumper;
11
12 our $VERSION = '0.024';
13
14 my %opt;
15
16 GetOptions( \%opt,
17 qw{
18 encoding=s indent=i locations! margin=i
19 perl_version|perl-version! ppi! short!
20 significant! tokens! variables!
21 },
22 'whitespace!' => sub {
23 $opt{significant} = !$_[1];
24 return;
25 },
26 help => sub { pod2usage( { -verbose => 2 } ) },
27 ) or pod2usage( { -verbose => 0 } );
28
29 defined $opt{encoding}
30 and binmode STDOUT, ":encoding($opt{encoding})";
31
32 my @dumper_arg = map { $_ => $opt{$_} } qw{
33 encoding indent locations margin perl_version ppi
34 short significant tokens variables
35 };
36
37 foreach my $arg ( @ARGV ) {
38 print PPIx::QuoteLike::Dumper->dump( $arg, @dumper_arg,
39 none => "$arg not recognized by PPIx::QuoteLike" );
40 }
41
42 __END__
43
44 =head1 TITLE
45
46 pqldump - Dump a quotelike thing
47
48 =head1 SYNOPSIS
49
50 pqldump '"foo$bar"'
51 pqldump fubar.pl
52 pqldump -help
53 pqldump -version
54
55 =head1 OPTIONS
56
57
58 =head2 -encoding
59
60 -encoding utf-8
61
62 This option specifies the encoding of the entities to be parsed, and of
63 the output. If unspecified, no encoding is assumed unless the input is a
64 file, in which case the file's encoding is derived from its PPI parse.
65
66 =head2 -help
67
68 This option displays the documentation for this script. The script then
69 exits.
70
71 =head2 -indent
72
73 -indent 4
74
75 This option controls the number of spaces each level of structure is
76 indented.
77
78 The default is C<-indent 2>.
79
80 =head2 -locations
81
82 If this Boolean option is true the locations of the tokens will be
83 dumped.
84
85 =head2 -margin
86
87 -margin 2
88
89 This option controls the number of spaces of left margin.
90
91 The default is C<-margin 0>.
92
93 =head2 -perl-version
94
95 If asserted, this option causes the minimum Perl version (and the
96 maximum if applicable) to be dumped.
97
98 The defualt is C<-noperl-version>.
99
100 =head2 -ppi
101
102 If asserted, this option causes a PPI dump on any interpolations found.
103 L<PPI|PPI> must be installed for this to work.
104
105 The default is C<-noppi>.
106
107 =head2 -short
108
109 If this option is asserted, leading C<'PPIx::QuoteLike::'> will be
110 removed from the class names in the output.
111
112 The default is C<-noshort>.
113
114 =head2 -significant
115
116 If this option is asserted, only significant tokens are dumped. As of
117 version 0.004, this only has effect in combination with C<-tokens>,
118 since all tokens interior to the string are significant.
119
120 The default is C<-nosignificant>.
121
122 =head2 -tokens
123
124 If asserted, an unstructured dump of the tokens found is done.
125
126 The default is C<-notokens>.
127
128 =head2 -variables
129
130 If asserted, this option causes the names of variables interpolated by
131 any interpolations found to be dumped. L<PPI|PPI> must be installed for
132 this to work.
133
134 The default is C<-novariables>.
135
136 =head2 -version
137
138 This option displays the version of this script. The script then exits.
139
140 =head2 -whitespace
141
142 This option is the inverse of L<-significant|/-significant>, and is
143 added for quasi-compatibility with the L<Perl::Critic|Perl::Critic>
144 C<ppidump> tool.
145
146 The default is (and must be) C<-whitespace>.
147
148 =head1 DETAILS
149
150 This Perl script is a command-line interface to
151 L<PPIx::QuoteLike::Dumper|PPIx::QuoteLike::Dumper>'s
152 L<dump()|PPIx::QuoteLike::Dumper/dump> method. The arguments can be
153 either literals or files. For files, all literals in the file are
154 dumped.
155
156 =head1 AUTHOR
157
158 Thomas R. Wyant, III F<harryfmudd at comcast dot net>
159
160 =head1 COPYRIGHT AND LICENSE
161
162 Copyright (C) 2016-2022, 2026 by Thomas R. Wyant, III
163
164 This program is free software; you can redistribute it and/or modify it
165 under the same terms as Perl 5.10.0. For more details, see the full text
166 of the licenses in the files F<LICENSE-Artistic> and F<LICENSE-GPL>.
167
168 This program is distributed in the hope that it will be useful, but
169 without any warranty; without even the implied warranty of
170 merchantability or fitness for a particular purpose.
171
172 =cut
173
174 # ex: set textwidth=72 :