line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Aniki::Filter; |
2
|
34
|
|
|
34
|
|
391094
|
use 5.014002; |
|
34
|
|
|
|
|
139
|
|
3
|
|
|
|
|
|
|
|
4
|
34
|
|
|
34
|
|
4903
|
use namespace::autoclean; |
|
34
|
|
|
|
|
115710
|
|
|
34
|
|
|
|
|
220
|
|
5
|
34
|
|
|
34
|
|
5588
|
use Mouse v2.4.5; |
|
34
|
|
|
|
|
164777
|
|
|
34
|
|
|
|
|
231
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has global_inflators => ( |
8
|
|
|
|
|
|
|
is => 'ro', |
9
|
|
|
|
|
|
|
default => sub { [] }, |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has global_deflators => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => sub { [] }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has global_triggers => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
default => sub { +{} }, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has table_inflators => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => sub { +{} }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has table_deflators => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
default => sub { +{} }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has table_triggers => ( |
33
|
|
|
|
|
|
|
is => 'ro', |
34
|
|
|
|
|
|
|
default => sub { +{} }, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
121
|
|
|
121
|
|
452
|
sub _identity { $_[0] } |
38
|
76
|
100
|
|
76
|
|
1225
|
sub _normalize_column2rx { ref $_[0] eq 'Regexp' ? $_[0] : qr/\A\Q$_[0]\E\z/m } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub add_global_inflator { |
41
|
6
|
|
|
6
|
0
|
61
|
my ($self, $column, $code) = @_; |
42
|
6
|
|
|
|
|
22
|
my $rx = _normalize_column2rx($column); |
43
|
6
|
|
|
|
|
12
|
push @{ $self->global_inflators } => [$rx, $code]; |
|
6
|
|
|
|
|
36
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub add_global_deflator { |
47
|
6
|
|
|
6
|
0
|
54
|
my ($self, $column, $code) = @_; |
48
|
6
|
|
|
|
|
16
|
my $rx = _normalize_column2rx($column); |
49
|
6
|
|
|
|
|
12
|
push @{ $self->global_deflators } => [$rx, $code]; |
|
6
|
|
|
|
|
29
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub add_global_trigger { |
53
|
2
|
|
|
2
|
0
|
24
|
my ($self, $event, $code) = @_; |
54
|
2
|
|
|
|
|
4
|
push @{ $self->global_triggers->{$event} } => $code; |
|
2
|
|
|
|
|
16
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub add_table_inflator { |
58
|
32
|
|
|
32
|
0
|
159
|
my ($self, $table_name, $column, $code) = @_; |
59
|
32
|
|
|
|
|
135
|
my $rx = _normalize_column2rx($column); |
60
|
32
|
|
|
|
|
101
|
push @{ $self->table_inflators->{$table_name} } => [$rx, $code]; |
|
32
|
|
|
|
|
255
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_table_deflator { |
64
|
32
|
|
|
32
|
0
|
135
|
my ($self, $table_name, $column, $code) = @_; |
65
|
32
|
|
|
|
|
104
|
my $rx = _normalize_column2rx($column); |
66
|
32
|
|
|
|
|
93
|
push @{ $self->table_deflators->{$table_name} } => [$rx, $code]; |
|
32
|
|
|
|
|
233
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub add_table_trigger { |
70
|
2
|
|
|
2
|
0
|
27
|
my ($self, $table_name, $event, $code) = @_; |
71
|
2
|
|
|
|
|
7
|
push @{ $self->table_triggers->{$table_name}->{$event} } => $code; |
|
2
|
|
|
|
|
17
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub inflate_column { |
75
|
203
|
|
|
203
|
0
|
496
|
my ($self, $table_name, $column, $data) = @_; |
76
|
203
|
|
|
|
|
576
|
my $code = $self->get_inflate_callback($table_name, $column); |
77
|
203
|
100
|
|
|
|
1470
|
return $data unless defined $code; |
78
|
34
|
|
|
|
|
122
|
return $code->($data); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub deflate_column { |
82
|
198
|
|
|
198
|
0
|
447
|
my ($self, $table_name, $column, $data) = @_; |
83
|
198
|
|
|
|
|
497
|
my $code = $self->get_deflate_callback($table_name, $column); |
84
|
198
|
100
|
|
|
|
716
|
return $data unless defined $code; |
85
|
27
|
|
|
|
|
114
|
return $code->($data); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub inflate_row { |
89
|
46
|
|
|
46
|
0
|
10065
|
my ($self, $table_name, $row) = @_; |
90
|
46
|
|
|
|
|
172
|
my %row = %$row; |
91
|
46
|
|
|
|
|
143
|
for my $column (keys %row) { |
92
|
46
|
|
|
|
|
139
|
$row{$column} = $self->inflate_column($table_name, $column, $row{$column}); |
93
|
|
|
|
|
|
|
} |
94
|
46
|
|
|
|
|
361
|
return \%row; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub deflate_row { |
98
|
155
|
|
|
155
|
0
|
4851
|
my ($self, $table_name, $row) = @_; |
99
|
155
|
|
|
|
|
499
|
my %row = %$row; |
100
|
155
|
|
|
|
|
474
|
for my $column (keys %row) { |
101
|
198
|
|
|
|
|
606
|
$row{$column} = $self->deflate_column($table_name, $column, $row{$column}); |
102
|
|
|
|
|
|
|
} |
103
|
155
|
|
|
|
|
804
|
return \%row; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub apply_trigger { |
107
|
121
|
|
|
121
|
0
|
365
|
my ($self, $event, $table_name, $row) = @_; |
108
|
121
|
|
|
|
|
514
|
my %row = %$row; |
109
|
|
|
|
|
|
|
|
110
|
121
|
|
|
|
|
420
|
my $trigger = $self->get_trigger_callback($event, $table_name); |
111
|
121
|
|
|
|
|
342
|
return $trigger->(\%row); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub get_inflate_callback { |
115
|
203
|
|
|
203
|
0
|
465
|
my ($self, $table_name, $column) = @_; |
116
|
203
|
100
|
|
|
|
1326
|
unless (exists $self->{__inflate_callbacks_cache}->{$table_name}->{$column}) { |
117
|
71
|
|
|
|
|
148
|
my $callback; |
118
|
71
|
|
|
|
|
133
|
for my $pair (@{ $self->global_inflators }) { |
|
71
|
|
|
|
|
298
|
|
119
|
28
|
|
|
|
|
74
|
my ($rx, $code) = @$pair; |
120
|
28
|
100
|
|
|
|
201
|
$callback = $code if $column =~ $rx; |
121
|
|
|
|
|
|
|
} |
122
|
71
|
|
|
|
|
155
|
for my $pair (@{ $self->table_inflators->{$table_name} }) { |
|
71
|
|
|
|
|
321
|
|
123
|
40
|
|
|
|
|
121
|
my ($rx, $code) = @$pair; |
124
|
40
|
100
|
|
|
|
301
|
$callback = $code if $column =~ $rx; |
125
|
|
|
|
|
|
|
} |
126
|
71
|
|
|
|
|
227
|
$self->{__inflate_callbacks_cache}->{$table_name}->{$column} = $callback; |
127
|
|
|
|
|
|
|
} |
128
|
203
|
|
|
|
|
477
|
return $self->{__inflate_callbacks_cache}->{$table_name}->{$column}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub get_deflate_callback { |
132
|
198
|
|
|
198
|
0
|
379
|
my ($self, $table_name, $column) = @_; |
133
|
198
|
100
|
|
|
|
712
|
unless (exists $self->{__deflate_callbacks_cache}->{$table_name}->{$column}) { |
134
|
77
|
|
|
|
|
167
|
my $callback; |
135
|
77
|
|
|
|
|
205
|
for my $pair (@{ $self->global_deflators }) { |
|
77
|
|
|
|
|
317
|
|
136
|
28
|
|
|
|
|
63
|
my ($rx, $code) = @$pair; |
137
|
28
|
100
|
|
|
|
183
|
$callback = $code if $column =~ $rx; |
138
|
|
|
|
|
|
|
} |
139
|
77
|
|
|
|
|
167
|
for my $pair (@{ $self->table_deflators->{$table_name} }) { |
|
77
|
|
|
|
|
314
|
|
140
|
41
|
|
|
|
|
115
|
my ($rx, $code) = @$pair; |
141
|
41
|
100
|
|
|
|
322
|
$callback = $code if $column =~ $rx; |
142
|
|
|
|
|
|
|
} |
143
|
77
|
|
|
|
|
223
|
$self->{__deflate_callbacks_cache}->{$table_name}->{$column} = $callback; |
144
|
|
|
|
|
|
|
} |
145
|
198
|
|
|
|
|
468
|
return $self->{__deflate_callbacks_cache}->{$table_name}->{$column}; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub get_trigger_callback { |
149
|
121
|
|
|
121
|
0
|
280
|
my ($self, $event, $table_name) = @_; |
150
|
|
|
|
|
|
|
|
151
|
121
|
100
|
|
|
|
539
|
unless (exists $self->{__trigger_callback_cache}->{$table_name}->{$event}) { |
152
|
|
|
|
|
|
|
my @triggers = ( |
153
|
33
|
100
|
|
|
|
355
|
@{ $self->table_triggers->{$table_name}->{$event} || [] }, |
154
|
33
|
100
|
|
|
|
81
|
@{ $self->global_triggers->{$event} || [] }, |
|
33
|
|
|
|
|
302
|
|
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
33
|
|
|
|
|
118
|
my $trigger = \&_identity; |
158
|
33
|
|
|
|
|
101
|
for my $cb (reverse @triggers) { |
159
|
6
|
|
|
|
|
11
|
my $next = $trigger; |
160
|
6
|
|
|
12
|
|
29
|
$trigger = sub { $cb->($_[0], $next) }; |
|
12
|
|
|
|
|
45
|
|
161
|
|
|
|
|
|
|
} |
162
|
33
|
|
|
|
|
133
|
$self->{__trigger_callback_cache}->{$table_name}->{$event} = $trigger; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
121
|
|
|
|
|
304
|
return $self->{__trigger_callback_cache}->{$table_name}->{$event}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
169
|
|
|
|
|
|
|
__END__ |