1 package PPI::Token::Operator;
7 PPI::Token::Operator - Token class for operators
17 # This is the list of valid operators
20 << >> lt gt le ge cmp ~~
29 All operators in PPI are created as C<PPI::Token::Operator> objects,
30 including the ones that may superficially look like a L<PPI::Token::Word>
35 There are no additional methods beyond those provided by the parent
36 L<PPI::Token> and L<PPI::Element> classes.
38 Got any ideas for methods? Submit a report to rt.cpan.org!
45 use vars qw{$VERSION @ISA %OPERATOR};
50 # Build the operator index
51 ### NOTE - This is accessed several times explicitly
52 ### in PPI::Token::Word. Do not rename this
53 ### without also correcting them.
54 %OPERATOR = map { $_ => 1 } (
59 == != <=> eq ne cmp ~~
61 ? : = += -= *= .= /= //=
64 }, ',' # Avoids "comma in qw{}" warning
72 #####################################################################
75 sub __TOKENIZER__on_char {
77 my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
79 # Are we still an operator if we add the next character
80 my $content = $t->{token}->{content};
81 return 1 if $OPERATOR{ $content . $char };
83 # Handle the special case of a .1234 decimal number
84 if ( $content eq '.' ) {
85 if ( $char =~ /^[0-9]$/ ) {
86 # This is a decimal number
87 $t->{class} = $t->{token}->set_class('Number::Float');
88 return $t->{class}->__TOKENIZER__on_char( $t );
92 # Handle the special case if we might be a here-doc
93 if ( $content eq '<<' ) {
94 my $line = substr( $t->{line}, $t->{line_cursor} );
95 # Either <<FOO or << 'FOO' or <<\FOO
96 ### Is the zero-width look-ahead assertion really
97 ### supposed to be there?
98 if ( $line =~ /^(?: (?!\d)\w | \s*['"`] | \\\w ) /x ) {
100 # Change the class and move to the HereDoc's own __TOKENIZER__on_char method.
101 $t->{class} = $t->{token}->set_class('HereDoc');
102 return $t->{class}->__TOKENIZER__on_char( $t );
106 # Handle the special case of the null Readline
107 if ( $content eq '<>' ) {
108 $t->{class} = $t->{token}->set_class('QuoteLike::Readline');
112 $t->_finalize_token->__TOKENIZER__on_char( $t );
121 See the L<support section|PPI/SUPPORT> in the main module.
125 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
129 Copyright 2001 - 2009 Adam Kennedy.
131 This program is free software; you can redistribute
132 it and/or modify it under the same terms as Perl itself.
134 The full text of the license can be found in the
135 LICENSE file included with this module.