line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TableDataRole::Munge::Filter; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
494
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
6
|
1
|
|
|
1
|
|
1688
|
use Log::ger; |
|
1
|
|
|
|
|
50
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
258
|
use Role::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
11
|
|
|
|
|
|
|
our $DATE = '2023-02-24'; # DATE |
12
|
|
|
|
|
|
|
our $DIST = 'TableDataRoles-Standard'; # DIST |
13
|
|
|
|
|
|
|
our $VERSION = '0.015'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
with 'TableDataRole::Spec::Basic'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
2
|
|
|
2
|
1
|
582
|
require Module::Load::Util; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
1640
|
my ($class, %args) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $tabledata = delete $args{tabledata} |
23
|
2
|
50
|
|
|
|
12
|
or die "Please supply 'tabledata' argument"; |
24
|
2
|
|
|
|
|
5
|
my $filter = delete $args{filter}; |
25
|
2
|
|
|
|
|
13
|
my $filter_hashref = delete $args{filter_hashref}; |
26
|
2
|
50
|
66
|
|
|
11
|
($filter || $filter_hashref) or die "Please supply 'filter' or 'filter_hashref' argument"; |
27
|
2
|
|
|
|
|
8
|
for ($filter, $filter_hashref) { |
28
|
4
|
100
|
|
|
|
11
|
next unless defined; |
29
|
2
|
50
|
|
|
|
7
|
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
|
|
|
|
7
|
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
|
|
|
|
|
18
|
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
|
|
|
|
|
28
|
|
|
2
|
|
|
|
|
6
|
|
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
|
10
|
my $self = shift; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
4
|
scalar @{ $self->{column_names} }; |
|
2
|
|
|
|
|
11
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_column_names { |
60
|
2
|
|
|
2
|
0
|
5
|
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
|
|
77
|
my $self = shift; |
66
|
50
|
100
|
|
|
|
96
|
return if $self->{buffer}; |
67
|
29
|
|
|
|
|
47
|
while (1) { |
68
|
191
|
100
|
|
|
|
1208
|
return unless $self->{tabledata}->has_next_item; |
69
|
189
|
100
|
|
|
|
408
|
if ($self->{filter}) { |
70
|
90
|
|
|
|
|
191
|
my $row = $self->{tabledata}->get_next_row_arrayref; |
71
|
90
|
100
|
|
|
|
200
|
if ($self->{filter}->($row)) { |
72
|
15
|
|
|
|
|
124
|
$self->{buffer} = $row; |
73
|
15
|
|
|
|
|
27
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} else { |
76
|
99
|
|
|
|
|
206
|
my $row = $self->{tabledata}->get_next_item; |
77
|
99
|
|
|
|
|
152
|
my $row_hashref = { map {$self->{column_names}[$_] => $row->[$_]} 0..$#{$row} }; |
|
297
|
|
|
|
|
756
|
|
|
99
|
|
|
|
|
191
|
|
78
|
99
|
100
|
|
|
|
262
|
if ($self->{filter_hashref}->($row_hashref)) { |
79
|
12
|
|
|
|
|
64
|
$self->{buffer} = $row; |
80
|
12
|
|
|
|
|
32
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub has_next_item { |
87
|
23
|
|
|
23
|
0
|
76
|
my $self = shift; |
88
|
23
|
50
|
|
|
|
43
|
return 1 if $self->{buffer}; |
89
|
23
|
|
|
|
|
51
|
$self->_fill_buffer; |
90
|
23
|
100
|
|
|
|
76
|
return $self->{buffer} ? 1:0; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_next_item { |
94
|
27
|
|
|
27
|
0
|
95
|
my $self = shift; |
95
|
27
|
|
|
|
|
60
|
$self->_fill_buffer; |
96
|
27
|
50
|
|
|
|
53
|
die "StopIteration" unless $self->{buffer}; |
97
|
27
|
|
|
|
|
37
|
$self->{pos}++; |
98
|
27
|
|
|
|
|
78
|
return delete $self->{buffer}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub get_next_row_hashref { |
102
|
4
|
|
|
4
|
0
|
10
|
my $self = shift; |
103
|
4
|
|
|
|
|
9
|
my $row = $self->get_next_item; |
104
|
4
|
|
|
|
|
10
|
+{ map {($self->{column_names}->[$_] => $row->[$_])} 0..$#{$row} }; |
|
12
|
|
|
|
|
62
|
|
|
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
|
29
|
my $self = shift; |
114
|
6
|
|
|
|
|
22
|
$self->{tabledata}->reset_iterator; |
115
|
6
|
|
|
|
|
17
|
$self->{pos} = 0; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
# ABSTRACT: Role to filter rows from another tabledata |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |