| 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 PPI::Document; |
| 11 |
use PPIx::QuoteLike::Utils qw{ __variables }; |
| 12 |
|
| 13 |
our $VERSION = '0.024'; |
| 14 |
|
| 15 |
my %opt; |
| 16 |
|
| 17 |
GetOptions( \%opt, |
| 18 |
help => sub { pod2usage( { -verbose => 2 } ) }, |
| 19 |
) and @ARGV == 1 or pod2usage( { -verbose => 0 } ); |
| 20 |
|
| 21 |
my $doc = PPI::Document->new( -e $ARGV[0] ? $ARGV[0] : \$ARGV[0] ); |
| 22 |
{ |
| 23 |
local $\ = "\n"; |
| 24 |
print for map { $_->[0] } |
| 25 |
sort { $a->[2] cmp $b->[2] || $a->[1] cmp $b->[1] } |
| 26 |
map { [ $_, substr( $_, 0, 1 ), substr( $_, 1 ) ] } |
| 27 |
__variables( $doc ); |
| 28 |
} |
| 29 |
|
| 30 |
__END__ |
| 31 |
|
| 32 |
=head1 TITLE |
| 33 |
|
| 34 |
variables - List the variables in a chunk of Perl |
| 35 |
|
| 36 |
=head1 SYNOPSIS |
| 37 |
|
| 38 |
variables eg/variables |
| 39 |
variables 'qr/foo$bar/smx' |
| 40 |
variables -help |
| 41 |
variables -version |
| 42 |
|
| 43 |
=head1 OPTIONS |
| 44 |
|
| 45 |
=head2 -help |
| 46 |
|
| 47 |
This option displays the documentation for this script. The script then |
| 48 |
exits. |
| 49 |
|
| 50 |
=head2 -version |
| 51 |
|
| 52 |
This option displays the version of this script. The script then exits. |
| 53 |
|
| 54 |
=head1 DETAILS |
| 55 |
|
| 56 |
This Perl script lists the variables in the chunk of Perl specified as |
| 57 |
the only command argument. This can be either the name of a file or |
| 58 |
literal Perl code; the choice is a pragmatic one based on whether a file |
| 59 |
by the given name actually exists. |
| 60 |
|
| 61 |
The output is in alphabetical order by variable name, and within |
| 62 |
variable name by sigil. In the case of subscripted variables, the sigil |
| 63 |
displayed will be that of the underlying variable. That is, if |
| 64 |
C<$foo[0]> appears, C<@foo> will be displayed. |
| 65 |
|
| 66 |
This script will find variables appearing in the code, and variables |
| 67 |
interpolated into strings. If L<PPIx::Regexp|PPIx::Regexp> can be |
| 68 |
loaded, variables interpolated into regular expressions will also be |
| 69 |
found. |
| 70 |
|
| 71 |
The heavy lifting is done by |
| 72 |
L<PPIx::QuoteLike::Utils|PPIx::QuoteLike::Utils> subroutine |
| 73 |
L<__variables()|PPIx::QuoteLike::Utils/__variables>. |
| 74 |
|
| 75 |
B<NOTE> that the C<__variables()> subroutine is discouraged, and may be |
| 76 |
deprecated and removed. |
| 77 |
|
| 78 |
=head1 AUTHOR |
| 79 |
|
| 80 |
Thomas R. Wyant, III F<harryfmudd at comcast dot net> |
| 81 |
|
| 82 |
=head1 COPYRIGHT AND LICENSE |
| 83 |
|
| 84 |
Copyright (C) 2019-2022, 2026 by Thomas R. Wyant, III |
| 85 |
|
| 86 |
This program is free software; you can redistribute it and/or modify it |
| 87 |
under the same terms as Perl 5.10.0. For more details, see the full text |
| 88 |
of the licenses in the files F<LICENSE-Artistic> and F<LICENSE-GPL>. |
| 89 |
|
| 90 |
This program is distributed in the hope that it will be useful, but |
| 91 |
without any warranty; without even the implied warranty of |
| 92 |
merchantability or fitness for a particular purpose. |
| 93 |
|
| 94 |
=cut |
| 95 |
|
| 96 |
# ex: set textwidth=72 : |