GA/MetaFunction.pm untested

filter: Statementstmt 0.0% 0 / 11 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 19 CC 2 SCAR 13.9
CC
2
Cov
0%
metabit1
6.0
new
2.0
do
2.0
CRAP 4.0
1 package Evo::GA::MetaFunction;
2  
3 sub new {
4 my ($class, $func) = @_;
5  
6 my $self = { function => &$func, };
7 }
8  
9 sub do {
10 my ($self, $genome, @args) = @_;
11  
12 ### &$self->{function}($genome)
13 return $self->{function}->($genome, @args);
14 }
15  
16  
17 ### several example meta bit functions (should normally be called before
18 ### mutation and cross-over)
19  
20 ### if bit is 1, mutate it
21 sub metabit1($genome, @args) {
22  
23 for (my $i = 0; $i < scalar @args; $i++) {
24 if (@args[$i] == 1) {
25 $genome->mutate_simple($i);
26 }
27 }
28  
29 return $genome;
30 }
31  
32 1;