line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TableDataRole::Munge::Filter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
601
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
1960
|
use Log::ger; |
|
1
|
|
|
|
|
59
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
244
|
use Role::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
11
|
|
|
|
|
|
|
our $DATE = '2022-02-20'; # DATE |
12
|
|
|
|
|
|
|
our $DIST = 'TableDataRoles-Standard'; # DIST |
13
|
|
|
|
|
|
|
our $VERSION = '0.014'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'TableDataRole::Spec::Basic'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
629
|
require Module::Load::Util; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
1216
|
my ($class, %args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $tabledata = delete $args{tabledata} |
23
|
2
|
50
|
|
|
|
11
|
or die "Please supply 'tabledata' argument"; |
24
|
2
|
|
|
|
|
7
|
my $filter = delete $args{filter}; |
25
|
2
|
|
|
|
|
6
|
my $filter_hashref = delete $args{filter_hashref}; |
26
|
2
|
50
|
66
|
|
|
13
|
($filter || $filter_hashref) or die "Please supply 'filter' or 'filter_hashref' argument"; |
27
|
2
|
|
|
|
|
6
|
for ($filter, $filter_hashref) { |
28
|
4
|
100
|
|
|
|
11
|
next unless defined; |
29
|
2
|
50
|
|
|
|
10
|
unless (ref $_ eq 'CODE') { |
30
|
0
|
|
|
|
|
0
|
my $code = "package main; sub { no strict; no warnings; $_ }"; |
31
|
0
|
|
|
|
|
0
|
log_trace "Eval-ing: $code"; |
32
|
0
|
|
|
|
|
0
|
$_ = eval $code; ## no critic: BuiltinFunctions::ProhibitStringyEval |
33
|
0
|
0
|
|
|
|
0
|
die if $@; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
2
|
50
|
|
|
|
10
|
die "Unknown argument(s): ". join(", ", sort keys %args) |
37
|
|
|
|
|
|
|
if keys %args; |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
12
|
$tabledata = Module::Load::Util::instantiate_class_with_optional_args({ns_prefix=>"TableData"}, $tabledata); |
40
|
2
|
|
|
|
|
25
|
my $column_names = $tabledata->get_column_names; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
bless { |
43
|
|
|
|
|
|
|
tabledata => $tabledata, |
44
|
|
|
|
|
|
|
column_names => $column_names, |
45
|
2
|
|
|
|
|
7
|
column_idxs => {map {$column_names->[$_] => $_} 0..$#{$column_names}}, |
|
6
|
|
|
|
|
32
|
|
|
2
|
|
|
|
|
7
|
|
46
|
|
|
|
|
|
|
filter => $filter, |
47
|
|
|
|
|
|
|
filter_hashref => $filter_hashref, |
48
|
|
|
|
|
|
|
pos => 0, # iterator |
49
|
|
|
|
|
|
|
# buffer => undef, |
50
|
|
|
|
|
|
|
}, $class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub get_column_count { |
54
|
2
|
|
|
2
|
0
|
11
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
4
|
scalar @{ $self->{column_names} }; |
|
2
|
|
|
|
|
15
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_column_names { |
60
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
61
|
2
|
50
|
|
|
|
7
|
wantarray ? @{ $self->{column_names} } : $self->{column_names}; |
|
2
|
|
|
|
|
19
|
|
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _fill_buffer { |
65
|
50
|
|
|
50
|
|
48
|
my $self = shift; |
66
|
50
|
100
|
|
|
|
82
|
return if $self->{buffer}; |
67
|
29
|
|
|
|
|
30
|
while (1) { |
68
|
191
|
100
|
|
|
|
794
|
return unless $self->{tabledata}->has_next_item; |
69
|
189
|
100
|
|
|
|
316
|
if ($self->{filter}) { |
70
|
90
|
|
|
|
|
132
|
my $row = $self->{tabledata}->get_next_row_arrayref; |
71
|
90
|
100
|
|
|
|
148
|
if ($self->{filter}->($row)) { |
72
|
15
|
|
|
|
|
64
|
$self->{buffer} = $row; |
73
|
15
|
|
|
|
|
21
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} else { |
76
|
99
|
|
|
|
|
148
|
my $row = $self->{tabledata}->get_next_item; |
77
|
99
|
|
|
|
|
113
|
my $row_hashref = { map {$self->{column_names}[$_] => $row->[$_]} 0..$#{$row} }; |
|
297
|
|
|
|
|
549
|
|
|
99
|
|
|
|
|
142
|
|
78
|
99
|
100
|
|
|
|
193
|
if ($self->{filter_hashref}->($row_hashref)) { |
79
|
12
|
|
|
|
|
48
|
$self->{buffer} = $row; |
80
|
12
|
|
|
|
|
23
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub has_next_item { |
87
|
23
|
|
|
23
|
0
|
63
|
my $self = shift; |
88
|
23
|
50
|
|
|
|
34
|
return 1 if $self->{buffer}; |
89
|
23
|
|
|
|
|
36
|
$self->_fill_buffer; |
90
|
23
|
100
|
|
|
|
65
|
return $self->{buffer} ? 1:0; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_next_item { |
94
|
27
|
|
|
27
|
0
|
65
|
my $self = shift; |
95
|
27
|
|
|
|
|
49
|
$self->_fill_buffer; |
96
|
27
|
50
|
|
|
|
37
|
die "StopIteration" unless $self->{buffer}; |
97
|
27
|
|
|
|
|
30
|
$self->{pos}++; |
98
|
27
|
|
|
|
|
62
|
return delete $self->{buffer}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_next_row_hashref { |
102
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
103
|
4
|
|
|
|
|
10
|
my $row = $self->get_next_item; |
104
|
4
|
|
|
|
|
7
|
+{ map {($self->{column_names}->[$_] => $row->[$_])} 0..$#{$row} }; |
|
12
|
|
|
|
|
47
|
|
|
4
|
|
|
|
|
8
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get_iterator_pos { |
108
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
109
|
0
|
|
|
|
|
0
|
$self->{pos}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub reset_iterator { |
113
|
6
|
|
|
6
|
0
|
35
|
my $self = shift; |
114
|
6
|
|
|
|
|
24
|
$self->{tabledata}->reset_iterator; |
115
|
6
|
|
|
|
|
13
|
$self->{pos} = 0; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
# ABSTRACT: Role to filter rows from another tabledata |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |