This file is indexed.

/usr/share/perl5/PPIx/Utilities/Statement.pm is in libppix-utilities-perl 1.001000-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
##############################################################################
#      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/PPIx-Utilities/lib/PPIx/Utilities/Statement.pm $
#     $Date: 2010-11-13 14:25:12 -0600 (Sat, 13 Nov 2010) $
#   $Author: clonezone $
# $Revision: 3990 $
##############################################################################

package PPIx::Utilities::Statement;

use 5.006001;
use strict;
use warnings;

our $VERSION = '1.001000';

use Readonly;


use PPI 1.208 qw< >; # Just for the version check.

use base 'Exporter';

our @EXPORT_OK = qw(
    get_constant_name_elements_from_declaring_statement
);


Readonly::Hash my %IS_COMMA => ( q[,] => 1, q[=>] => 1 );


sub get_constant_name_elements_from_declaring_statement {
    my ($element) = @_;

    return if not $element;
    return if not $element->isa('PPI::Statement');

    if ( $element->isa('PPI::Statement::Include') ) {
        my $pragma;
        if ( $pragma = $element->pragma() and $pragma eq 'constant' ) {
            return _get_constant_names_from_constant_pragma($element);
        } # end if
    } elsif ( not $element->specialized() and $element->schildren() > 2 ) {
        my $supposed_constant_function = $element->schild(0)->content();
        my $declaring_scope = $element->schild(1)->content();

        if (
                (
                        $supposed_constant_function eq 'const'
                    or  $supposed_constant_function =~ m< \A Readonly \b >xms
                )
            and ($declaring_scope eq 'our' or $declaring_scope eq 'my')
        ) {
            return $element->schild(2);
        } # end if
    } # end if

    return;
} # end get_constant_name_elements_from_declaring_statement()


sub _get_constant_names_from_constant_pragma {
    my ($include) = @_;

    my @arguments = $include->arguments() or return;

    my $follower = $arguments[0];
    return if not defined $follower;

    # We test for a 'PPI::Structure::Block' in the following because some
    # versions of PPI parse the last element of 'use constant { ONE => 1, TWO
    # => 2 }' as a block rather than a constructor. As of PPI 1.206, PPI
    # handles the above correctly, but still blows it on 'use constant 1.16 {
    # ONE => 1, TWO => 2 }'.
    if (
            $follower->isa( 'PPI::Structure::Constructor' )
        or  $follower->isa( 'PPI::Structure::Block' )
    ) {
        my $statement = $follower->schild( 0 ) or return;
        $statement->isa( 'PPI::Statement' ) or return;

        my @elements;
        my $inx = 0;
        foreach my $child ( $statement->schildren() ) {
            if (not $inx % 2) {
                push @{ $elements[ $inx ] ||= [] }, $child;
            } # end if

            if ( $IS_COMMA{ $child->content() } ) {
                $inx++;
            } # end if
        } # end foreach

        return map
            {
                (
                        $_
                    and @{$_} == 2
                    and '=>' eq $_->[1]->content()
                    and $_->[0]->isa( 'PPI::Token::Word' )
                )
                    ? $_->[0]
                    : ()
            }
            @elements;
    } else {
        return $follower;
    } # end if

    return $follower;
} # end _get_constant_names_from_constant_pragma()


1;

__END__

=pod

=for stopwords

=head1 NAME

PPIx::Utilities::Statement - Extensions to L<PPI::Statement|PPI::Statement>.


=head1 VERSION

This document describes PPIx::Utilities::Statement version 1.1.0.


=head1 SYNOPSIS

    use PPI::Document qw< >;

    use PPIx::Utilities::Statement qw<
        get_constant_name_elements_from_declaring_statement
    >;

    my $document = PPI::Document->new(\'Readonly::Scalar my $THINGY => 47.2;');

    # Returns the PPI::Token::Symbol for "$THINGY".
    my ($constant) = get_constant_name_elements_from_declaring_statement(
        $document->schild(0)
    );


=head1 DESCRIPTION

This is a collection of functions for dealing with
L<PPI::Statement|PPI::Statement>s.


=head1 INTERFACE

Nothing is exported by default.


=head2 C<get_constant_name_elements_from_declaring_statement($statement)>

Given a L<PPI::Statement|PPI::Statement>, if the statement is a
L<Readonly|Readonly> or L<Const::Fast|Const::Fast> declaration statement or a
C<use constant>, returns the names of the things being defined.

Given

    use constant 1.16 FOO => 'bar';

this will return the L<PPI::Token::Word|PPI::Token::Word> containing C<'FOO'>.
Given

    use constant 1.16 { FOO => 'bar', 'BAZ' => 'burfle' };

this will return a list of the L<PPI::Token|PPI::Token>s containing C<'FOO'>
and C<'BAZ'>. Similarly, given

    Readonly::Hash my %FOO => ( bar => 'baz' );

or

    const my %FOO => ( bar => 'baz' );

this will return the L<PPI::Token::Symbol|PPI::Token::Symbol> containing
C<'%FOO'>.


=head1 BUGS AND LIMITATIONS

Please report any bugs or feature requests to
C<bug-ppix-utilities@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.


=head1 AUTHOR

Thomas R. Wyant, III C<< <wyant at cpan dot org> >>


=head1 COPYRIGHT

Copyright (c) 2009-2010 Thomas R. Wyant, III.  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 :