/usr/share/perl5/PPI/Token/Structure.pm is in libppi-perl 1.215-1.
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 | package PPI::Token::Structure;
=pod
=head1 NAME
PPI::Token::Structure - Token class for characters that define code structure
=head1 INHERITANCE
PPI::Token::Structure
isa PPI::Token
isa PPI::Element
=head1 DESCRIPTION
The C<PPI::Token::Structure> class is used for tokens that control the
generally tree structure or code.
This consists of seven characters. These are the six brace characters from
the "round", "curly" and "square" pairs, plus the semi-colon statement
separator C<;>.
=head1 METHODS
This class has no methods beyond what is provided by its
L<PPI::Token> and L<PPI::Element> parent classes.
=cut
use strict;
use PPI::Token ();
use vars qw{$VERSION @ISA};
BEGIN {
$VERSION = '1.215';
@ISA = 'PPI::Token';
}
# Set the matching braces, done as an array
# for slightly faster lookups.
use vars qw{@MATCH @OPENS @CLOSES};
BEGIN {
$MATCH[ord '{'] = '}';
$MATCH[ord '}'] = '{';
$MATCH[ord '['] = ']';
$MATCH[ord ']'] = '[';
$MATCH[ord '('] = ')';
$MATCH[ord ')'] = '(';
$OPENS[ord '{'] = 1;
$OPENS[ord '['] = 1;
$OPENS[ord '('] = 1;
$CLOSES[ord '}'] = 1;
$CLOSES[ord ']'] = 1;
$CLOSES[ord ')'] = 1;
}
#####################################################################
# Tokenizer Methods
sub __TOKENIZER__on_char {
# Structures are one character long, always.
# Finalize and process again.
$_[1]->_finalize_token->__TOKENIZER__on_char( $_[1] );
}
sub __TOKENIZER__commit {
my $t = $_[1];
$t->_new_token( 'Structure', substr( $t->{line}, $t->{line_cursor}, 1 ) );
$t->_finalize_token;
0;
}
#####################################################################
# Lexer Methods
# For a given brace, find its opposing pair
sub __LEXER__opposite {
$MATCH[ord $_[0]->{content} ];
}
#####################################################################
# PPI::Element Methods
# There is a unusual situation in regards to "siblings".
#
# As an Element, braces sit outside the normal tree structure, and in
# this context they NEVER have siblings.
#
# However, as tokens they DO have siblings.
#
# As such, we need special versions of _all_ of the sibling methods to
# handle this.
#
# Statement terminators do not have these problems, and for them sibling
# calls work as normal, and so they can just be passed upwards.
sub next_sibling {
return $_[0]->SUPER::next_sibling if $_[0]->{content} eq ';';
return '';
}
sub snext_sibling {
return $_[0]->SUPER::snext_sibling if $_[0]->{content} eq ';';
return '';
}
sub previous_sibling {
return $_[0]->SUPER::previous_sibling if $_[0]->{content} eq ';';
return '';
}
sub sprevious_sibling {
return $_[0]->SUPER::sprevious_sibling if $_[0]->{content} eq ';';
return '';
}
sub next_token {
my $self = shift;
return $self->SUPER::next_token if $self->{content} eq ';';
my $structure = $self->parent or return '';
# If this is an opening brace, descend down into our parent
# structure, if it has children.
if ( $OPENS[ ord $self->{content} ] ) {
my $child = $structure->child(0);
if ( $child ) {
# Decend deeper, or return if it is a token
return $child->isa('PPI::Token') ? $child : $child->first_token;
} elsif ( $structure->finish ) {
# Empty structure, so next is closing brace
return $structure->finish;
}
# Anything that slips through to here is a structure
# with an opening brace, but no closing brace, so we
# just have to go with it, and continue as we would
# if we started with a closing brace.
}
# We can use the default implement, if we call it from the
# parent structure of the closing brace.
$structure->next_token;
}
sub previous_token {
my $self = shift;
return $self->SUPER::previous_token if $self->{content} eq ';';
my $structure = $self->parent or return '';
# If this is a closing brace, descend down into our parent
# structure, if it has children.
if ( $CLOSES[ ord $self->{content} ] ) {
my $child = $structure->child(-1);
if ( $child ) {
# Decend deeper, or return if it is a token
return $child->isa('PPI::Token') ? $child : $child->last_token;
} elsif ( $structure->start ) {
# Empty structure, so next is closing brace
return $structure->start;
}
# Anything that slips through to here is a structure
# with a closing brace, but no opening brace, so we
# just have to go with it, and continue as we would
# if we started with a opening brace.
}
# We can use the default implement, if we call it from the
# parent structure of the closing brace.
$structure->previous_token;
}
1;
=pod
=head1 SUPPORT
See the L<support section|PPI/SUPPORT> in the main module.
=head1 AUTHOR
Adam Kennedy E<lt>adamk@cpan.orgE<gt>
=head1 COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy.
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the
LICENSE file included with this module.
=cut
|