line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::Mutator::Generator; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13345
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
44
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
945
|
use PPI; |
|
2
|
|
|
|
|
178827
|
|
|
2
|
|
|
|
|
389
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %operators_map = ( |
9
|
|
|
|
|
|
|
'+' => '-', |
10
|
|
|
|
|
|
|
'==' => '!=', |
11
|
|
|
|
|
|
|
'++' => '--', |
12
|
|
|
|
|
|
|
'=~' => '!~', |
13
|
|
|
|
|
|
|
'*' => '/', |
14
|
|
|
|
|
|
|
'gt' => 'lt', |
15
|
|
|
|
|
|
|
'ge' => 'le', |
16
|
|
|
|
|
|
|
'>' => '<=', |
17
|
|
|
|
|
|
|
'>=' => '<', |
18
|
|
|
|
|
|
|
'||' => '&&', |
19
|
|
|
|
|
|
|
'and' => 'or', |
20
|
|
|
|
|
|
|
'eq' => 'ne', |
21
|
|
|
|
|
|
|
'//' => '||', |
22
|
|
|
|
|
|
|
'//=' => '||=', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
my %reversed_operators_map = reverse %operators_map; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub new { |
27
|
5
|
|
|
5
|
1
|
3220
|
my $class = shift; |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
8
|
my $self = {}; |
30
|
5
|
|
|
|
|
7
|
bless $self, $class; |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
12
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub generate { |
36
|
5
|
|
|
5
|
1
|
13
|
my $self = shift; |
37
|
5
|
|
|
|
|
7
|
my ($code) = @_; |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
26
|
my $ppi = PPI::Document->new(\$code); |
40
|
|
|
|
|
|
|
|
41
|
5
|
|
|
|
|
3650
|
my @mutants; |
42
|
5
|
50
|
|
|
|
17
|
if (my $operators = $ppi->find('PPI::Token::Operator')) { |
43
|
5
|
|
|
|
|
1321
|
foreach my $operator (@$operators) { |
44
|
5
|
|
|
|
|
13
|
my $new_operator = find_map($operator->content); |
45
|
|
|
|
|
|
|
|
46
|
5
|
50
|
|
|
|
13
|
next unless $new_operator; |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
10
|
my $old_operator = $operator->content; |
49
|
5
|
|
|
|
|
22
|
$operator->set_content($new_operator); |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
20
|
push @mutants, |
52
|
|
|
|
|
|
|
{ |
53
|
|
|
|
|
|
|
id => $ppi->hex_id, |
54
|
|
|
|
|
|
|
content => $ppi->serialize |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
584
|
$operator->set_content($old_operator); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
30
|
return @mutants; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub find_map { |
65
|
5
|
|
|
5
|
1
|
18
|
my ($operator) = @_; |
66
|
|
|
|
|
|
|
|
67
|
5
|
50
|
|
|
|
18
|
return $operators_map{$operator} if exists $operators_map{$operator}; |
68
|
|
|
|
|
|
|
return $reversed_operators_map{$operator} |
69
|
0
|
0
|
|
|
|
|
if exists $reversed_operators_map{$operator}; |
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |