line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Statistics::Swoop; |
2
|
4
|
|
|
4
|
|
132404
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
194
|
|
3
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
125
|
|
4
|
4
|
|
|
4
|
|
22
|
use Carp qw/croak/; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
535
|
|
5
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
6
|
4
|
|
|
|
|
43
|
rw => [qw/list/], |
7
|
|
|
|
|
|
|
ro => [qw/count max min range sum avg/], |
8
|
4
|
|
|
4
|
|
15251
|
); |
|
4
|
|
|
|
|
18613
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
9
|
|
|
9
|
1
|
8172
|
my ($class, $list) = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
100
|
|
|
|
208
|
croak "first arg is required as array ref" unless ref($list) eq 'ARRAY'; |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
|
|
37
|
my $self = bless +{ |
18
|
|
|
|
|
|
|
list => $list, |
19
|
8
|
|
|
|
|
14
|
count => scalar @{$list}, |
20
|
|
|
|
|
|
|
} => $class; |
21
|
|
|
|
|
|
|
|
22
|
8
|
100
|
|
|
|
30
|
$self->_calc if $self->count; |
23
|
8
|
|
|
|
|
32
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _calc { |
27
|
7
|
|
|
7
|
|
64
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
|
|
14
|
my $sum; |
30
|
7
|
|
|
|
|
24
|
my $max = $self->list->[0]; |
31
|
7
|
|
|
|
|
47
|
my $min = $self->list->[0]; |
32
|
7
|
|
|
|
|
27
|
my $range; |
33
|
|
|
|
|
|
|
my $avg; |
34
|
|
|
|
|
|
|
|
35
|
7
|
|
|
|
|
69
|
for my $i (@{$self->list}) { |
|
7
|
|
|
|
|
20
|
|
36
|
24
|
|
|
|
|
52
|
$sum += $i; |
37
|
24
|
100
|
|
|
|
65
|
if ($max < $i) { |
|
|
100
|
|
|
|
|
|
38
|
15
|
|
|
|
|
25
|
$max = $i; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ($min > $i) { |
41
|
2
|
|
|
|
|
6
|
$min = $i; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
7
|
100
|
|
|
|
26
|
if ($self->count == 1) { |
|
|
50
|
|
|
|
|
|
46
|
2
|
|
|
|
|
18
|
$self->{range} = $max; |
47
|
2
|
|
|
|
|
6
|
$self->{avg} = $max; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($self->count > 1) { |
50
|
5
|
|
|
|
|
72
|
$self->{range} = $max - $min; |
51
|
5
|
|
|
|
|
15
|
$self->{avg} = $sum / $self->count; |
52
|
|
|
|
|
|
|
} |
53
|
7
|
|
|
|
|
43
|
$self->{sum} = $sum; |
54
|
7
|
|
|
|
|
16
|
$self->{max} = $max; |
55
|
7
|
|
|
|
|
19
|
$self->{min} = $min; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
4
|
|
|
4
|
1
|
25
|
sub maximum { $_[0]->max } |
59
|
4
|
|
|
4
|
1
|
3117
|
sub minimum { $_[0]->min } |
60
|
4
|
|
|
4
|
1
|
4549
|
sub average { $_[0]->avg } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub result { |
63
|
1
|
|
|
1
|
1
|
10
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return +{ |
66
|
1
|
|
|
|
|
4
|
count => $self->count, |
67
|
|
|
|
|
|
|
max => $self->max, |
68
|
|
|
|
|
|
|
min => $self->min, |
69
|
|
|
|
|
|
|
range => $self->range, |
70
|
|
|
|
|
|
|
sum => $self->sum, |
71
|
|
|
|
|
|
|
avg => $self->avg, |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |