line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Homogeneous; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
36683
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
5
|
use base 'Exporter'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
118
|
|
6
|
1
|
|
|
1
|
|
1541
|
use Clone qw/ clone /; |
|
1
|
|
|
|
|
11153
|
|
|
1
|
|
|
|
|
122
|
|
7
|
|
|
|
|
|
|
use overload |
8
|
1
|
|
|
|
|
8
|
'<>' => \&_get, |
9
|
1
|
|
|
1
|
|
1806
|
fallback => 1; |
|
1
|
|
|
|
|
1577
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw/ homogeneous /; |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw/ homo /; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub homogeneous { |
17
|
4
|
|
|
4
|
0
|
7
|
my $r = shift; |
18
|
4
|
100
|
|
|
|
58
|
my $array = ref $_[0] eq 'ARRAY' ? $_[0] : \@_; |
19
|
4
|
50
|
|
|
|
13
|
die if $r < 0; |
20
|
4
|
50
|
|
|
|
9
|
return [] if $r == 0; |
21
|
4
|
100
|
|
|
|
11
|
return [ map { [ $_ ] } @$array ] if $r == 1; |
|
4
|
|
|
|
|
15
|
|
22
|
2
|
|
|
|
|
10
|
my $homo = &homogeneous($r-1, $array); |
23
|
2
|
|
|
|
|
4
|
my $return = []; |
24
|
2
|
|
|
|
|
5
|
foreach my $h (@$homo) { |
25
|
4
|
|
|
|
|
7
|
for (@$array) { |
26
|
8
|
|
|
|
|
60
|
my $clone_h = clone $h; |
27
|
8
|
|
|
|
|
14
|
push @$clone_h, $_; |
28
|
8
|
|
|
|
|
20
|
push @$return, $clone_h; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
2
|
|
|
|
|
8
|
$return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
0
|
1600
|
sub homo { homogeneous @_ } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
1
|
|
|
1
|
0
|
2553
|
my $class = shift; |
38
|
1
|
|
|
|
|
3
|
my $homo = homogeneous @_; |
39
|
1
|
|
|
|
|
6
|
my $iterator = { |
40
|
|
|
|
|
|
|
current => 0, |
41
|
|
|
|
|
|
|
length => scalar @$homo, |
42
|
|
|
|
|
|
|
iteratee => $homo, |
43
|
|
|
|
|
|
|
}; |
44
|
1
|
|
|
|
|
14
|
bless($iterator, $class); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _next { |
48
|
1
|
|
|
1
|
|
3
|
my $self = shift; |
49
|
1
|
50
|
|
|
|
4
|
return undef unless $self->_has_next; |
50
|
1
|
|
|
|
|
5
|
$self->{iteratee}[$self->{current}++]; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _has_next { |
54
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
55
|
1
|
|
|
|
|
6
|
$self->{current} < $self->{length}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _get { |
59
|
1
|
|
|
1
|
|
70
|
my $self = shift; |
60
|
1
|
50
|
|
|
|
5
|
wantarray ? @{$self->{iteratee}} : $self->_next; |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |