Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / PPI / Token / Operator.pm
1 package PPI::Token::Operator;
2
3 =pod
4
5 =head1 NAME
6
7 PPI::Token::Operator - Token class for operators
8
9 =head1 INHERITANCE
10
11   PPI::Token::Operator
12   isa PPI::Token
13       isa PPI::Element
14
15 =head1 SYNOPSIS
16
17   # This is the list of valid operators
18   ++   --   **   !    ~    +    -
19   =~   !~   *    /    %    x
20   <<   >>   lt   gt   le   ge   cmp  ~~
21   ==   !=   <=>  .    ..   ...  ,
22   &    |    ^    &&   ||   //
23   ?    :    =    +=   -=   *=   .=   //=
24   <    >    <=   >=   <>   =>   ->
25   and  or   dor  not  eq   ne
26
27 =head1 DESCRIPTION
28
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>
31 object.
32
33 =head1 METHODS
34
35 There are no additional methods beyond those provided by the parent
36 L<PPI::Token> and L<PPI::Element> classes.
37
38 Got any ideas for methods? Submit a report to rt.cpan.org!
39
40 =cut
41
42 use strict;
43 use PPI::Token ();
44
45 use vars qw{$VERSION @ISA %OPERATOR};
46 BEGIN {
47         $VERSION = '1.206';
48         @ISA     = 'PPI::Token';
49
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 } (
55                 qw{
56                 -> ++ -- ** ! ~ + -
57                 =~ !~ * / % x . << >>
58                 < > <= >= lt gt le ge
59                 == != <=> eq ne cmp ~~
60                 & | ^ && || // .. ...
61                 ? : = += -= *= .= /= //=
62                 => <>
63                 and or xor not
64                 }, ','  # Avoids "comma in qw{}" warning
65                 );
66 }
67
68
69
70
71
72 #####################################################################
73 # Tokenizer Methods
74
75 sub __TOKENIZER__on_char {
76         my $t    = $_[1];
77         my $char = substr( $t->{line}, $t->{line_cursor}, 1 );
78
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 };
82
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 );
89                 }
90         }
91
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 ) {
99                         # This is a here-doc.
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 );
103                 }
104         }
105
106         # Handle the special case of the null Readline
107         if ( $content eq '<>' ) {
108                 $t->{class} = $t->{token}->set_class('QuoteLike::Readline');
109         }
110
111         # Finalize normally
112         $t->_finalize_token->__TOKENIZER__on_char( $t );
113 }
114
115 1;
116
117 =pod
118
119 =head1 SUPPORT
120
121 See the L<support section|PPI/SUPPORT> in the main module.
122
123 =head1 AUTHOR
124
125 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
126
127 =head1 COPYRIGHT
128
129 Copyright 2001 - 2009 Adam Kennedy.
130
131 This program is free software; you can redistribute
132 it and/or modify it under the same terms as Perl itself.
133
134 The full text of the license can be found in the
135 LICENSE file included with this module.
136
137 =cut