line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::DOM58::_Collection; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Mojo::DOM58 which is released under: |
4
|
|
|
|
|
|
|
# The Artistic License 2.0 (GPL Compatible) |
5
|
|
|
|
|
|
|
# See the documentation for Mojo::DOM58 for full license details. |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
67913
|
use strict; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
88
|
|
8
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
89
|
|
9
|
3
|
|
|
3
|
|
16
|
use Carp 'croak'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
211
|
|
10
|
3
|
|
|
3
|
|
21
|
use List::Util; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
238
|
|
11
|
3
|
|
|
3
|
|
21
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
26
|
|
|
3
|
|
|
|
|
300
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
50
|
|
3
|
|
22
|
use constant REDUCE => ($] >= 5.008009 ? \&List::Util::reduce : \&_reduce); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
377
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Role support requires Role::Tiny 2.000001+ |
16
|
|
|
|
|
|
|
use constant ROLES => |
17
|
3
|
|
|
3
|
|
22
|
!!(eval { require Role::Tiny; Role::Tiny->VERSION('2.000001'); 1 }); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1714
|
|
|
3
|
|
|
|
|
12778
|
|
|
3
|
|
|
|
|
2286
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '2.000'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
708
|
|
|
708
|
0
|
3475
|
my $class = shift; |
23
|
708
|
|
66
|
|
|
7403
|
return bless [@_], ref $class || $class; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
0
|
50
|
sub TO_JSON { [@{shift()}] } |
|
1
|
|
|
|
|
4
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub compact { |
29
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
30
|
3
|
100
|
66
|
|
|
7
|
return $self->new(grep { defined && (ref || length) } @$self); |
|
9
|
|
|
|
|
36
|
|
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub each { |
34
|
115
|
|
|
115
|
0
|
790
|
my ($self, $cb) = @_; |
35
|
115
|
100
|
|
|
|
323
|
return @$self unless $cb; |
36
|
105
|
|
|
|
|
166
|
my $i = 1; |
37
|
105
|
|
|
|
|
350
|
$_->$cb($i++) for @$self; |
38
|
105
|
|
|
|
|
206
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub first { |
42
|
75
|
|
|
75
|
0
|
1190
|
my ($self, $cb) = (shift, shift); |
43
|
75
|
100
|
|
|
|
324
|
return $self->[0] unless $cb; |
44
|
11
|
100
|
|
2
|
|
30
|
return List::Util::first { $_ =~ $cb } @$self if ref $cb eq 'Regexp'; |
|
2
|
|
|
|
|
13
|
|
45
|
10
|
|
|
22
|
|
41
|
return List::Util::first { $_->$cb(@_) } @$self; |
|
22
|
|
|
|
|
69
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
5
|
0
|
12
|
sub flatten { $_[0]->new(_flatten(@{$_[0]})) } |
|
5
|
|
|
|
|
16
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub grep { |
51
|
35
|
|
|
35
|
0
|
99
|
my ($self, $cb) = (shift, shift); |
52
|
35
|
100
|
|
|
|
132
|
return $self->new(grep { $_ =~ $cb } @$self) if ref $cb eq 'Regexp'; |
|
9
|
|
|
|
|
34
|
|
53
|
34
|
|
|
|
|
73
|
return $self->new(grep { $_->$cb(@_) } @$self); |
|
106
|
|
|
|
|
337
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub join { |
57
|
41
|
100
|
|
41
|
0
|
114
|
join +(defined($_[1]) ? $_[1] : ''), map {"$_"} @{$_[0]}; |
|
97
|
|
|
|
|
317
|
|
|
41
|
|
|
|
|
92
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
19
|
|
|
19
|
0
|
108
|
sub last { shift->[-1] } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub map { |
63
|
46
|
|
|
46
|
0
|
126
|
my ($self, $cb) = (shift, shift); |
64
|
46
|
|
|
|
|
107
|
return $self->new(map { $_->$cb(@_) } @$self); |
|
96
|
|
|
|
|
303
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub reduce { |
68
|
3
|
|
|
3
|
0
|
515
|
my $self = shift; |
69
|
3
|
|
|
|
|
10
|
@_ = (@_, @$self); |
70
|
3
|
|
|
|
|
6
|
goto &{REDUCE()}; |
|
3
|
|
|
|
|
18
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
8
|
|
|
8
|
0
|
20
|
sub reverse { $_[0]->new(reverse @{$_[0]}) } |
|
8
|
|
|
|
|
18
|
|
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
2
|
0
|
179
|
sub shuffle { $_[0]->new(List::Util::shuffle @{$_[0]}) } |
|
2
|
|
|
|
|
308
|
|
76
|
|
|
|
|
|
|
|
77
|
52
|
|
|
52
|
0
|
117
|
sub size { scalar @{$_[0]} } |
|
52
|
|
|
|
|
240
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub slice { |
80
|
8
|
|
|
8
|
0
|
19
|
my $self = shift; |
81
|
8
|
|
|
|
|
24
|
return $self->new(@$self[@_]); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub sort { |
85
|
6
|
|
|
6
|
0
|
26
|
my ($self, $cb) = @_; |
86
|
|
|
|
|
|
|
|
87
|
6
|
100
|
|
|
|
21
|
return $self->new(sort @$self) unless $cb; |
88
|
|
|
|
|
|
|
|
89
|
4
|
|
|
|
|
9
|
my $caller = caller; |
90
|
3
|
|
|
3
|
|
27
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1550
|
|
91
|
|
|
|
|
|
|
my @sorted = sort { |
92
|
4
|
|
|
|
|
27
|
local (*{"${caller}::a"}, *{"${caller}::b"}) = (\$a, \$b); |
|
12
|
|
|
|
|
37
|
|
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
24
|
|
93
|
12
|
|
|
|
|
24
|
$a->$cb($b); |
94
|
|
|
|
|
|
|
} @$self; |
95
|
4
|
|
|
|
|
20
|
return $self->new(@sorted); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub tap { |
99
|
2
|
|
|
2
|
0
|
8
|
my ($self, $cb) = (shift, shift); |
100
|
2
|
|
|
|
|
9
|
$_->$cb(@_) for $self; |
101
|
2
|
|
|
|
|
11
|
return $self; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
39
|
|
|
39
|
0
|
73
|
sub to_array { [@{shift()}] } |
|
39
|
|
|
|
|
192
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub uniq { |
107
|
7
|
|
|
7
|
0
|
37
|
my ($self, $cb) = (shift, shift); |
108
|
7
|
|
|
|
|
9
|
my %seen; |
109
|
7
|
100
|
|
|
|
19
|
return $self->new(grep { my $r = $_->$cb(@_); !$seen{defined $r ? $r : ''}++ } @$self) if $cb; |
|
12
|
100
|
|
|
|
25
|
|
|
12
|
|
|
|
|
49
|
|
110
|
4
|
100
|
|
|
|
8
|
return $self->new(grep { !$seen{defined $_ ? $_ : ''}++ } @$self); |
|
27
|
|
|
|
|
74
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub with_roles { |
114
|
2
|
|
|
2
|
0
|
4
|
croak 'Role::Tiny 2.000001+ is required for roles' unless ROLES; |
115
|
2
|
|
|
|
|
6
|
my ($self, @roles) = @_; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return Role::Tiny->create_class_with_roles($self, |
118
|
2
|
50
|
|
|
|
12
|
map { /^\+(.+)$/ ? "${self}::Role::$1" : $_ } @roles) |
|
1
|
100
|
|
|
|
9
|
|
119
|
|
|
|
|
|
|
unless my $class = blessed $self; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
return Role::Tiny->apply_roles_to_object($self, |
122
|
1
|
50
|
|
|
|
3
|
map { /^\+(.+)$/ ? "${class}::Role::$1" : $_ } @roles); |
|
1
|
|
|
|
|
10
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _flatten { |
126
|
16
|
100
|
|
16
|
|
33
|
map { _ref($_) ? _flatten(@$_) : $_ } @_; |
|
41
|
|
|
|
|
64
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# For perl < 5.8.9 |
130
|
|
|
|
|
|
|
sub _reduce (&@) { |
131
|
0
|
|
|
0
|
|
0
|
my $code = shift; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
0
|
return shift unless @_ > 1; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
my $caller = caller; |
136
|
|
|
|
|
|
|
|
137
|
3
|
|
|
3
|
|
25
|
no strict 'refs'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
497
|
|
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
0
|
local (*{"${caller}::a"}, *{"${caller}::b"}) = (\my $x, \my $y); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
0
|
$x = shift; |
142
|
0
|
|
|
|
|
0
|
foreach my $e (@_) { |
143
|
0
|
|
|
|
|
0
|
$y = $e; |
144
|
0
|
|
|
|
|
0
|
$x = $code->(); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
$x; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
41
|
100
|
100
|
41
|
|
236
|
sub _ref { ref $_[0] eq 'ARRAY' || blessed $_[0] && $_[0]->isa(__PACKAGE__) } |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=for Pod::Coverage *EVERYTHING* |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |