… | |
… | |
29 | |
29 | |
30 | =cut |
30 | =cut |
31 | |
31 | |
32 | package Perl::Strip; |
32 | package Perl::Strip; |
33 | |
33 | |
34 | our $VERSION = '1.1'; |
34 | our $VERSION = '1.2'; |
35 | our $CACHE_VERSION = 2; |
35 | our $CACHE_VERSION = 3; |
36 | |
36 | |
37 | use common::sense; |
37 | use common::sense; |
38 | |
38 | |
39 | use PPI; |
39 | use PPI; |
40 | |
40 | |
… | |
… | |
132 | my $next = $ws->next_token; |
132 | my $next = $ws->next_token; |
133 | |
133 | |
134 | if (!$prev || !$next) { |
134 | if (!$prev || !$next) { |
135 | $ws->delete; |
135 | $ws->delete; |
136 | } else { |
136 | } else { |
|
|
137 | if ($next->isa (PPI::Token::Whitespace::)) { |
|
|
138 | $ws->delete; |
137 | if ( |
139 | } elsif ( |
138 | $next->isa (PPI::Token::Operator::) && $next->{content} =~ /^(?:,|=|!|!=|==|=>)$/ # no ., because of digits. == float |
140 | $next->isa (PPI::Token::Operator::) && $next->{content} =~ /^(?:,|=|!|!=|==|=>)$/ # no ., because of digits. == float |
139 | or $prev->isa (PPI::Token::Operator::) && $prev->{content} =~ /^(?:,|=|\.|!|!=|==|=>)$/ |
141 | or $prev->isa (PPI::Token::Operator::) && $prev->{content} =~ /^(?:,|=|\.|!|!=|==|=>)$/ |
140 | or $prev->isa (PPI::Token::Structure::) |
142 | or $prev->isa (PPI::Token::Structure::) |
141 | or ($self->{optimise_size} && |
143 | or ($self->{optimise_size} && |
142 | ($prev->isa (PPI::Token::Word::) |
144 | ($prev->isa (PPI::Token::Word::) |
… | |
… | |
144 | || $next->isa (PPI::Structure::Block::) |
146 | || $next->isa (PPI::Structure::Block::) |
145 | || $next->isa (PPI::Structure::List::) |
147 | || $next->isa (PPI::Structure::List::) |
146 | || $next->isa (PPI::Structure::Condition::))) |
148 | || $next->isa (PPI::Structure::Condition::))) |
147 | ) |
149 | ) |
148 | ) { |
150 | ) { |
|
|
151 | # perl has some idiotic warnigns about nonexisting operators |
|
|
152 | if ($prev->isa (PPI::Token::Operator::) && $prev->{content} eq "=" |
|
|
153 | && $next->isa (PPI::Token::Operator::) && $next->{content} =~ /[+\-]/ |
|
|
154 | ) { |
|
|
155 | # avoid "Reverse %s operator" diagnostic |
|
|
156 | } else { |
149 | $ws->delete; |
157 | $ws->delete; |
150 | } elsif ($prev->isa (PPI::Token::Whitespace::)) { |
158 | } |
151 | $ws->{content} = ' '; |
|
|
152 | $prev->delete; |
|
|
153 | } else { |
159 | } else { |
154 | $ws->{content} = ' '; |
160 | $ws->{content} = ' '; |
155 | } |
161 | } |
156 | } |
162 | } |
157 | } |
163 | } |