line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Enumerator::Base; |
2
|
9
|
|
|
9
|
|
49
|
use strict; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
312
|
|
3
|
9
|
|
|
9
|
|
44
|
use warnings; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
463
|
|
4
|
9
|
|
|
9
|
|
53
|
use Scalar::Util qw/blessed/; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
1595
|
|
5
|
9
|
|
|
9
|
|
80
|
use constant LAST => bless {},'Data::Enumerator::Base::LAST'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
10374
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
78
|
|
|
78
|
0
|
246
|
my ( $class,$object) = @_; |
9
|
78
|
|
|
|
|
595
|
return bless { |
10
|
|
|
|
|
|
|
object => $object, |
11
|
|
|
|
|
|
|
},$class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub object { |
15
|
10099
|
|
|
10099
|
0
|
32689
|
shift->{object} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub is_last { |
19
|
21854
|
|
100
|
21854
|
0
|
123041
|
return (ref $_[1] and ref $_[1] eq 'Data::Enumerator::Base::LAST'); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub iterator { |
24
|
950
|
|
|
950
|
0
|
1525
|
my ( $self ) = @_; |
25
|
950
|
|
|
|
|
1429
|
my $count = 0; |
26
|
|
|
|
|
|
|
return sub{ |
27
|
5465
|
100
|
|
5465
|
|
6366
|
return LAST if ($count >= scalar( @{$self->object})); |
|
5465
|
|
|
|
|
10728
|
|
28
|
4552
|
|
|
|
|
9642
|
$self->object->[$count++]; |
29
|
950
|
|
|
|
|
5670
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub each { |
33
|
24
|
|
|
24
|
0
|
46
|
my ( $self,$f) = @_; |
34
|
24
|
|
|
|
|
101
|
my $iter = $self->iterator; |
35
|
24
|
|
|
|
|
41
|
while(1){ |
36
|
417
|
|
|
|
|
1208
|
my $result = $iter->(); |
37
|
417
|
100
|
|
|
|
5160
|
last if( $self->is_last( $result )); |
38
|
393
|
|
|
|
|
750
|
my $value = $f->( $result ); |
39
|
393
|
50
|
|
|
|
8467
|
last if( $self->is_last( $value )); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub select { |
44
|
6
|
|
|
6
|
0
|
37
|
my ( $self,$mapper ) = @_; |
45
|
6
|
|
|
|
|
4020
|
require Data::Enumerator::Mapper; |
46
|
6
|
|
|
|
|
59
|
return Data::Enumerator::Mapper->new([$self,$mapper]); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub where { |
50
|
14
|
|
|
14
|
0
|
26
|
my ( $self,$predicate ) = @_; |
51
|
14
|
|
|
|
|
3389
|
require Data::Enumerator::Where; |
52
|
14
|
|
|
|
|
78
|
return Data::Enumerator::Where->new([$self,$predicate]); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub take { |
56
|
2
|
|
|
2
|
0
|
4
|
my ( $self,$num ) = @_; |
57
|
2
|
|
|
|
|
14
|
return $self->limit(0,$num); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub take_while { |
61
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $predicate ) = @_; |
62
|
2
|
|
|
|
|
4
|
my $flag = 1; |
63
|
|
|
|
|
|
|
return $self->where( |
64
|
|
|
|
|
|
|
sub { |
65
|
16
|
100
|
|
16
|
|
44
|
return $self->LAST unless $flag; |
66
|
14
|
|
|
|
|
33
|
my $result = $predicate->(@_); |
67
|
14
|
100
|
|
|
|
63
|
$flag = 0 unless $result; |
68
|
14
|
|
|
|
|
30
|
return $result; |
69
|
|
|
|
|
|
|
} |
70
|
2
|
|
|
|
|
15
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub skip_while { |
74
|
1
|
|
|
1
|
0
|
4
|
my ( $self, $predicate ) = @_; |
75
|
1
|
|
|
|
|
2
|
my $flag = 1; |
76
|
|
|
|
|
|
|
return $self->where( |
77
|
|
|
|
|
|
|
sub { |
78
|
20
|
100
|
|
20
|
|
44
|
return 1 unless $flag; |
79
|
10
|
|
|
|
|
21
|
my $result = not $predicate->(@_); |
80
|
10
|
100
|
|
|
|
40
|
$flag = 0 if $result; |
81
|
10
|
|
|
|
|
20
|
return $result; |
82
|
|
|
|
|
|
|
} |
83
|
1
|
|
|
|
|
7
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
sub repeat { |
86
|
3
|
|
|
3
|
0
|
16
|
my ($self) = @_; |
87
|
3
|
|
|
|
|
1514
|
require Data::Enumerator::Repeat; |
88
|
3
|
|
|
|
|
23
|
return Data::Enumerator::Repeat->new($self); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub to_array { |
92
|
5
|
|
|
5
|
0
|
63
|
return [ shift->list ]; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub limit { |
96
|
4
|
|
|
4
|
0
|
16
|
my ( $self,$offset,$limit ) = @_; |
97
|
4
|
|
|
|
|
2177
|
require Data::Enumerator::Limit; |
98
|
4
|
|
|
|
|
40
|
return Data::Enumerator::Limit->new([$self,$offset,$limit]); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub add { |
102
|
1
|
|
|
1
|
0
|
13
|
my ( $self ,$generator ) = @_; |
103
|
1
|
|
|
|
|
821
|
require Data::Enumerator::Add; |
104
|
1
|
|
|
|
|
10
|
return Data::Enumerator::Add->new([$self,$generator]); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub product { |
108
|
15
|
|
|
15
|
0
|
54
|
my ( $self,$generator) = @_; |
109
|
15
|
|
|
|
|
3724
|
require Data::Enumerator::Product; |
110
|
15
|
|
|
|
|
93
|
return Data::Enumerator::Product->new([$self,$generator]); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub list { |
114
|
23
|
|
|
23
|
0
|
1230
|
my ( $self ) = @_; |
115
|
23
|
|
|
|
|
35
|
my @list; |
116
|
|
|
|
|
|
|
$self->each(sub{ |
117
|
393
|
|
|
393
|
|
811
|
push @list ,shift; |
118
|
23
|
|
|
|
|
195
|
}); |
119
|
23
|
|
|
|
|
540
|
return @list; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; |