@@ -46,7 +46,7 @@ BEGIN {
46
46
# Tokenizer Methods
47
47
48
48
sub __TOKENIZER__on_char {
49
- my $t = $_ [1] ; # Tokenizer object
49
+ my ( $self , $t ) = @_ ; # Self and Tokenizer
50
50
my $c = $t -> {token }-> {content }; # Current token
51
51
my $char = substr ( $t -> {line }, $t -> {line_cursor }, 1 ); # Current character
52
52
@@ -77,35 +77,7 @@ sub __TOKENIZER__on_char {
77
77
}
78
78
79
79
if ( $char eq ' $' ) {
80
- # Operator/operand-sensitive, multiple or GLOB cast
81
- my $_class;
82
- my $tokens = $t -> _previous_significant_tokens(1);
83
- my $p0 = $tokens -> [0];
84
- if ( $p0 ) {
85
- # Is it a token or a number
86
- if ( $p0 -> isa(' PPI::Token::Symbol' ) ) {
87
- $_class = ' Operator' ;
88
- } elsif ( $p0 -> isa(' PPI::Token::Number' ) ) {
89
- $_class = ' Operator' ;
90
- } elsif (
91
- $p0 -> isa(' PPI::Token::Structure' )
92
- and
93
- $p0 -> content =~ / ^(?:\) |\] )$ /
94
- ) {
95
- $_class = ' Operator' ;
96
- } else {
97
- # ## This is pretty weak, there's
98
- # ## room for a dozen more tests
99
- # ## before going with a default.
100
- # ## Or even better, a proper
101
- # ## operator/operand method :(
102
- $_class = ' Cast' ;
103
- }
104
- } else {
105
- # Nothing before it, must be glob cast
106
- $_class = ' Cast' ;
107
- }
108
-
80
+ my $_class = $self -> _cast_or_op( $t );
109
81
# Set class and rerun
110
82
$t -> {class } = $t -> {token }-> set_class( $_class );
111
83
return $t -> _finalize_token-> __TOKENIZER__on_char( $t );
@@ -283,7 +255,7 @@ sub __TOKENIZER__on_char {
283
255
# Now, : acts very very differently in different contexts.
284
256
# Mainly, we need to find out if this is a subroutine attribute.
285
257
# We'll leave a hint in the token to indicate that, if it is.
286
- if ( $_ [0] -> __TOKENIZER__is_an_attribute( $t ) ) {
258
+ if ( $self -> __TOKENIZER__is_an_attribute( $t ) ) {
287
259
# This : is an attribute indicator
288
260
$t -> {class } = $t -> {token }-> set_class( ' Operator' );
289
261
$t -> {token }-> {_attribute } = 1;
@@ -299,6 +271,28 @@ sub __TOKENIZER__on_char {
299
271
PPI::Exception-> throw(' Unknown value in PPI::Token::Unknown token' );
300
272
}
301
273
274
+ # Operator/operand-sensitive, multiple or GLOB cast
275
+ sub _cast_or_op {
276
+ my ( undef , $t ) = @_ ;
277
+ my ( $prev ) = @{ $t -> _previous_significant_tokens(1) };
278
+ return ' Cast' if !$prev ;
279
+
280
+ return ' Operator' if
281
+ $prev -> isa(' PPI::Token::Symbol' )
282
+ or
283
+ $prev -> isa(' PPI::Token::Number' )
284
+ or
285
+ (
286
+ $prev -> isa(' PPI::Token::Structure' )
287
+ and
288
+ $prev -> content =~ / ^(?:\) |\] )$ /
289
+ );
290
+
291
+ # This is pretty weak, there's room for a dozen more tests before going with
292
+ # a default. Or even better, a proper operator/operand method :(
293
+ return ' Cast' ;
294
+ }
295
+
302
296
# Are we at a location where a ':' would indicate a subroutine attribute
303
297
sub __TOKENIZER__is_an_attribute {
304
298
my $t = $_ [1]; # Tokenizer object
0 commit comments