EvenlySpaced.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 104 CC 7 SCAR 26.5
CC
7
Cov
0%
plot
30.0
AUTOLOAD
12.0
new
2.0
CRAP 14.1
1 package GIFgraph::EvenlySpaced;
2  
3 use strict;
4  
5 use MRP::BaseClass;
6  
7 use vars qw(@ISA %fields $AUTOLOAD $VERSION);
8  
9 $VERSION = 1.0;
10  
11 sub AUTOLOAD {
12 my $thing = shift;
13 my ($package, $function) = $AUTOLOAD =~ m/^(.*)::([^:]+)$/;
14 return if $function eq 'DESTROY';
15  
16 if(ref($thing)) {
17 return $thing->_DelegateGraph->$function(@_);
18 }
19 # my $super = join '::', 'SUPER', $function;
20 # return $thing->$super(@_);
21 die "Could not find $AUTOLOAD via $thing ";
22 }
23  
24 sub new {
25 my $class = shift;
26 my $graph = shift;
27 my $self = new MRP::BaseClass;
28 $self->rebless($class);
29 $self->_DelegateGraph($graph);
30 return $self;
31 }
32  
33 sub plot {
34 my ($self, $data) = @_;
35 my $fudge = $self->fudge;
36 my @processed;
37  
38 my @x = @{$data->[0]};
39 my @distances;
40 my ($min, $max) = ($x[0], $x[$#x]);
41 my $len = $max-$min;
42 foreach my $i (1 .. $#x) {
43 $distances[$i-1] = $x[$i] - $x[$i-1];
44 }
45 my @sdist = sort { $a<=>$b } @distances;
46  
47 my $sd = shift @sdist;
48 while(@sdist) {
49 my $nd = shift @sdist;
50 my $diff = $nd/$sd;
51 $diff = $diff - int($diff);
52 $diff = 1-$diff if $diff > 0.5;
53 next if $diff < $fudge;
54 my $rat = $nd/$sd;
55 my $continue = 1;
56 for(my $ax = 2; $continue; $ax++) {
57 my $yx = $ax*$rat;
58 if($yx !~ /\./) {
59 $sd = $nd/$yx;
60 $continue = 0;
61 }
62 }
63 }
64  
65 my $lowest = shift @x;
66 my $column = 0;
67 for(my $newX = $min; ($newX-$sd) < $max; $newX+=$sd) {
68 if($newX >= $lowest) {
69 foreach my $series (0 .. $#$data) {
70 push @{$processed[$series]}, $data->[$series][$column];
71 }
72 $column++;
73 $lowest = shift @x;
74 } else {
75 foreach my $series (0 .. $#$data) {
76 push @{$processed[$series]}, undef;
77 }
78 }
79 }
80  
81 local $^W = undef;
82 return $self->_DelegateGraph->plot(\@processed);
83 }
84  
85 sub isa {
86 my ($thing, $type) = @_;
87 return $thing->_DelegateGraph->isa($type) || $thing->SUPER::isa($type);
88 }
89  
90 BEGIN {
91 @ISA = qw(MRP::BaseClass);
92 %fields = (
93 fudge => 0.1,
94 _DelegateGraph => undef,
95 );
96 GIFgraph::EvenlySpaced->check4Clashes;
97 }
98  
99 $VERSION;
100  
101 __END__