blib/lib/OpenSMTPd/Filter.pm

filter: Statementstmt 99.5% 203 / 204 Branchbran 92.3% 72 / 78 Conditioncond 89.8% 53 / 59 MC/DCmcdc 80.0% 24 / 30 Subroutinesub 95.6% 22 / 23 Podpod 100% 2 / 2 totaltotal 94.9% 376 / 396 CC 77 SCAR 21.8
CC
77
Cov
96%
_handle_filter
16.0
_handle_report
13.0
_handle_filter_data_line
11.0
CRAP 8.9
↑ Summary
1 package OpenSMTPd::Filter;
2 5 ▶use utf8; # so literals and identifiers can be in UTF-8
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use v5.16; # or later to get "unicode_strings" feature and "charnames"
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict; # quote strings, declare variables
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings; # on by default
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings qw(FATAL utf8); # fatalize encoding glitches
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use open qw(:std :encoding(UTF-8)); # undeclared streams in UTF-8
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # This happens automatically, but to make pledge(2) happy
10 # it has to happen earlier than it would otherwise.
11 5 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Time::HiRes qw< time >;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Easier filters for OpenSMTPd in perl
17 5 our $VERSION = 'v0.0.2'; # VERSION
18  
19 5 my @report_fields = qw< version timestamp subsystem event session suffix >;
20 5 my %report_events = (
21 'smtp-in' => {
22 'link-connect' => [qw< rdns fcrdns src dest >],
23 'link-greeting' => [qw< hostname >],
24 'link-identify' => [qw< method identity >],
25 'link-tls' => [qw< tls-string >],
26 'link-disconnect' => [qw< >],
27 'link-auth' => [qw< username result >],
28 'tx-reset' => [qw< message-id >],
29 'tx-begin' => [qw< message-id >],
30 'tx-mail' => [qw< message-id result address >],
31 'tx-rcpt' => [qw< message-id result address>],
32 'tx-envelope' => [qw< message-id envelope-id >],
33 'tx-data' => [qw< message-id result >],
34 'tx-commit' => [qw< message-id message-size >],
35 'tx-rollback' => [qw< message-id >],
36 'protocol-client' => [qw< command >],
37 'protocol-server' => [qw< response >],
38 'filter-report' => [qw< filter-kind name message >],
39 'filter-response' => [qw< phase response param>],
40 'timeout' => [qw< >],
41 },
42 );
43  
44 my @filter_fields
45 5 = qw< version timestamp subsystem phase session opaque-token suffix >;
46 my %filter_events = (
47 'smtp-in' => {
48 'connect' => [qw< rdns fcrdns src dest >],
49 'helo' => [qw< identity >],
50 'ehlo' => [qw< identity >],
51 'starttls' => [qw< tls-string >],
52 'auth' => [qw< auth >],
53 'mail-from' => [qw< address >],
54 'rcpt-to' => [qw< address >],
55 'data' => [qw< >],
56 'data-line' => [qw< line >],
57 'commit' => [qw< >],
58  
59 0 ▶ 'data-lines' => sub {'data-line'}, # special case
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 },
61 5 );
62  
63 5 my @filter_result_fields = qw< session opaque-token >;
64 5 my %filter_result_decisions = (
65  
66 #'dataline' => [qw< line >], # special case
67 'proceed' => [qw< >],
68 'junk' => [qw< >],
69 'reject' => [qw< error >],
70 'disconnect' => [qw< error >],
71 'rewrite' => [qw< parameter >],
72 'report' => [qw< parameter >],
73 );
74  
75 sub new {
76 19 ▶ my ( $class, %params ) = @_;
Subroutine new: called CC=8 SCAR=20.8
Pod documented
77  
78 19 ▶ $params{on} ||= {};
Condition100%2/2
$params{"on"} ||= {}
l!l
109
MC/DC100%1/1
$params{"on"} ||= {}
$params{"on"}
Truth table100%2/2
A
A= $params{"on"}
Aresult
11
00
79 19 ▶ $params{input} ||= \*STDIN;
Condition100%2/2
$params{"input"} ||= \*STDIN
l!l
514
MC/DC100%1/1
$params{"input"} ||= \*STDIN
$params{"input"}
Truth table100%2/2
A
A= $params{"input"}
Aresult
11
00
80 19 ▶ $params{output} ||= \*STDOUT;
Condition100%2/2
$params{"output"} ||= \*STDOUT
l!l
109
MC/DC100%1/1
$params{"output"} ||= \*STDOUT
$params{"output"}
Truth table100%2/2
A
A= $params{"output"}
Aresult
11
00
81  
82 19 STDERR->autoflush;
83 19 $params{output}->autoflush;
84  
85 # We expect to read and write bytes from the remote
86 19 $_->binmode(':raw') for @params{qw< input output >};
87  
88 19 my $check_supported_events;
89 $check_supported_events = sub {
90 49 ▶ my ( $c, $e, $ms ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.1
91 49 ▶ my $m = shift @{$ms} || return;
Condition100%2/2
shift @{$ms;} || (return)
l!l
3613
MC/DC100%1/1
shift @{$ms;} || (return)
shift @{$ms;}
Truth table100%2/2
A
A= shift @{$ms;}
Aresult
11
00
92  
93 36 my @s = sort keys %{$c};
94 36 ▶ if ( my @u = grep { !$e->{$_} } @s ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@u) = grep({not $e->{$_};} @s)) 3 33 36
95 3 ▶ my $s = @u == 1 ? '' : 's';
Branch: 1 branch
BranchTrueFalseTotal
@u == 1 ? : 1 2 3
96 3 croak("Unsupported $m$s @u");
97 }
98  
99 33 $check_supported_events->( $c->{$_}, $e->{$_}, $ms ) for @s;
100 19 };
101  
102 $check_supported_events->(
103 $params{on},
104 19 { report => \%report_events, filter => \%filter_events },
105 [ "event type", "event subsystem", "event" ]
106 );
107  
108 # Only save data-lines if we're using the helper to process them
109 $params{_save_data_lines}
110 = $params{on}
111 && $params{on}{filter}
112 && $params{on}{filter}{'smtp-in'}
113 16 ▶ && $params{on}{filter}{'smtp-in'}{'data-lines'};
Condition77%7/9
$params{'on'} && $params{'on'}{'filter'} && $params{'on'}{'filter'}{'smtp-in'} && $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
!ll&&!rl&&r
1042
$params{"on"} and $params{"on"}{"filter"} and $params{"on"}{"filter"}{"smtp-in"}
!ll&&!rl&&r
1006
$params{"on"} and $params{"on"}{"filter"}
!ll&&!rl&&r
0106
MC/DC50%2/4
$params{'on'} && $params{'on'}{'filter'} && $params{'on'}{'filter'}{'smtp-in'} && $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
$params{"on"} $params{"on"}{"filter"} $params{"on"}{"filter"}{"smtp-in"} $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
Truth table60%3/5
A and B and C && D
A= $params{"on"}B= $params{"on"}{"filter"}C= $params{"on"}{"filter"}{"smtp-in"}D= $params{'on'}{'filter'}{'smtp-in'}{'data-lines'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
114  
115 16 my $self = bless \%params, $class;
116 16 return $self->_init;
117 }
118  
119 sub _init {
120 17 ▶ my ($self) = @_;
Subroutine _init: called CC=8 SCAR=21.0
121  
122 17 my $fh = $self->{input};
123 17 ▶ my $blocking = $fh->blocking // die "Unable to get blocking on input: $!";
Condition50%1/2
$fh->blocking // die("Unable to get blocking on input: $!")
l!l
170
MC/DC0%0/1
$fh->blocking // die("Unable to get blocking on input: $!")
$fh->blocking
Truth table50%1/2
A
A= $fh->blocking
Aresult
11
00
124 17 ▶ $fh->blocking(0) // die "Unable to set input to non-blocking: $!";
Condition50%1/2
$fh->blocking(0) // die("Unable to set input to non-blocking: $!")
l!l
170
MC/DC0%0/1
$fh->blocking(0) // die("Unable to set input to non-blocking: $!")
$fh->blocking(0)
Truth table50%1/2
A
A= $fh->blocking(0)
Aresult
11
00
125  
126 17 my $timeout = 0.25; # no idea how long we should actually wait
127 17 my $now = time;
128  
129 17 my %config;
130 17 ▶ while ( not $self->{_ready} and ( time - $now ) < $timeout ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_ready"} and &OpenSMTPd::Filter::time() - $now < $timeout) 462210 17 462227
Condition100%3/3
not $self->{"_ready"} and &OpenSMTPd::Filter::time() - $now < $timeout
!ll&&!rl&&r
611462210
MC/DC100%2/2
not $self->{"_ready"} and &OpenSMTPd::Filter::time() - $now < $timeout
not $self->{"_ready"} &OpenSMTPd::Filter::time() - $now < $timeout
Truth table100%3/3
not(A) and B
A= not $self->{"_ready"}B= &OpenSMTPd::Filter::time() - $now < $timeout
ABresult
0X0
100
111
131 462210 ▶ my $line = $fh->getline // next;
Condition100%2/2
$fh->getline // (next)
l!l
8462202
MC/DC100%1/1
$fh->getline // (next)
$fh->getline
Truth table100%2/2
A
A= $fh->getline
Aresult
11
00
132 8 ▶ STDERR->print("< $line") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
133 8 chomp $line;
134 8 $self->_dispatch($line);
135 8 $now = time; # continue waiting, we got a line
136 }
137  
138 17 ▶ $fh->blocking($blocking) // die "Unable to reset blocking on input: $!";
Condition50%1/2
$fh->blocking($blocking) // die("Unable to reset blocking on input: $!")
l!l
170
MC/DC0%0/1
$fh->blocking($blocking) // die("Unable to reset blocking on input: $!")
$fh->blocking($blocking)
Truth table50%1/2
A
A= $fh->blocking($blocking)
Aresult
11
00
139  
140 17 return $self;
141 }
142  
143 sub ready {
144 5 ▶ my ($self) = @_;
Subroutine ready: called CC=9 SCAR=22.1
Pod documented
145 5 ▶ croak("Input stream is not ready") unless $self->{_ready};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_ready"} 1 4 5
146  
147 76 my @reports = map {"report|smtp-in|$_"}
148 4 sort keys %{ $report_events{'smtp-in'} };
149  
150 4 my @filters;
151 4 for my $subsystem ( sort keys %{ $self->{on}->{filter} } ) {
152 1 for ( sort keys %{ $self->{on}->{filter}->{$subsystem} } ) {
153 1 my $v = $filter_events{$subsystem}{$_};
154 1 ▶ my $phase = ref $v eq 'CODE' ? $v->($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'CODE' ? : 0 1 1
155 1 push @filters, "filter|$subsystem|$phase";
156 }
157 }
158  
159 4 for ( @reports, @filters, 'ready' ) {
160 81 ▶ STDERR->say("> register|$_") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 81 81
161 81 $self->{output}->say("register|$_");
162 }
163  
164 4 $self->{input}->blocking(1);
165  
166 4 ▶ while ( defined( my $line = $self->{input}->getline ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->{"input"}->getline)) 98 4 102
167 98 ▶ STDERR->print("< $line") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 98 98
168 98 chomp $line;
169 98 $self->_dispatch($line);
170 }
171 }
172  
173 # The char "|" may only appear in the last field of a payload, in which
174 # case it should be considered a regular char and not a separator. Other
175 # fields have strict formatting excluding the possibility of having a "|".
176 sub _dispatch {
177 143 ▶ my ( $self, $line ) = @_;
Subroutine _dispatch: called CC=4 SCAR=13.9
178 143 ▶ $line //= 'undef'; # no unitialized warnings
Condition100%2/2
$line //= "undef"
l!l
1421
MC/DC100%1/1
$line //= "undef"
$line
Truth table100%2/2
A
A= $line
Aresult
11
00
179 143 my ( $type, $extra ) = split /\|/, $line, 2;
180 143 ▶ $type //= 'unsupported'; # no uninitialized warnings
Condition100%2/2
$type //= "unsupported"
l!l
1421
MC/DC100%1/1
$type //= "unsupported"
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
181  
182 143 my $method = $self->can("_handle_$type");
183 143 ▶ return $self->$method($extra) if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 140 3 143
184  
185 3 croak("Unsupported: $line");
186 }
187  
188 # general configuration information in the form of key-value lines
189 sub _handle_config {
190 10 ▶ my ( $self, $config ) = @_;
Subroutine _handle_config: called CC=2 SCAR=6.9
191  
192 10 ▶ return $self->{_ready} = $config
Branch: 1 branch
BranchTrueFalseTotal
if $config eq "ready" 5 5 10
193 if $config eq 'ready';
194  
195 5 my ( $key, $value ) = split /\|/, $config, 2;
196 5 $self->{_config}->{$key} = $value;
197  
198 5 return $key, $value;
199 }
200  
201 # Each report event is generated by smtpd(8) as a single line
202 #
203 # The format consists of a protocol prefix containing the stream, the
204 # protocol version, the timestamp, the subsystem, the event and the unique
205 # session identifier separated by "|":
206 #
207 # It is followed by a suffix containing the event-specific parameters, also
208 # separated by "|"
209  
210 sub _handle_report {
211 109 ▶ my ( $self, $report ) = @_;
Subroutine _handle_report: called CC=13 SCAR=25.6
212  
213 109 my %report;
214 109 @report{@report_fields} = split /\|/, $report, @report_fields;
215  
216 109 ▶ my $event = $report{event} // '';
Condition100%2/2
$report{"event"} // ""
l!l
1081
MC/DC100%1/1
$report{"event"} // ""
$report{"event"}
Truth table100%2/2
A
A= $report{"event"}
Aresult
11
00
217 109 my $suffix = delete $report{suffix};
218  
219 109 my %params;
220 109 my @fields = $self->_report_fields_for( @report{qw< subsystem event >} );
221 106 ▶ @params{@fields} = split /\|/, $suffix, @fields
Branch: 1 branch
BranchTrueFalseTotal
if @fields 101 5 106
222 if @fields;
223  
224 106 ▶ my $session = $self->{_sessions}->{ $report{session} } ||= {};
Condition100%2/2
$self->{"_sessions"}{$report{"session"}} ||= {}
l!l
1015
MC/DC100%1/1
$self->{"_sessions"}{$report{"session"}} ||= {}
$self->{"_sessions"}{$report{"session"}}
Truth table100%2/2
A
A= $self->{"_sessions"}{$report{"session"}}
Aresult
11
00
225 106 $session->{state}->{$_} = $report{$_} for keys %report;
226 106 push @{ $session->{events} }, { %report, %params, request => 'report' };
227  
228 # If the session disconncted we can't do anything more with it
229 delete $self->{_sessions}->{ $report{session} }
230 106 ▶ if $event eq 'link-disconnect';
Branch: 1 branch
BranchTrueFalseTotal
if $event eq "link-disconnect" 3 103 106
231  
232 106 ▶ if ( $event =~ /^tx-(.*)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($event =~ /^tx-(.*)$/u) { } 23 83 106
233 23 my $phase = $1;
234  
235 3 push @{ $session->{messages} }, $session->{state}->{message} = {}
236 23 ▶ if $phase eq 'begin';
Branch: 1 branch
BranchTrueFalseTotal
if $phase eq "begin" 3 20 23
237  
238 23 my $message = $session->{messages}->[-1];
239  
240 23 ▶ if ( $phase eq 'mail' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($phase eq 'mail') { } 3 20 23
elsif ($phase eq 'rcpt') { } 4 16 20
241 3 $message->{'mail-from'} = $params{address};
242 3 $message->{result} = $params{result};
243 }
244 elsif ( $phase eq 'rcpt') {
245 4 push @{ $message->{'rcpt-to'} }, $params{address};
246 4 $message->{result} = $params{result};
247 }
248 else {
249 16 $message->{$_} = $params{$_} for keys %params;
250 }
251 }
252 else {
253 83 $session->{state}->{$_} = $params{$_} for keys %params;
254 }
255  
256 106 my $cb = $self->_cb_for( report => @report{qw< subsystem event >} );
257 106 ▶ $cb->( $event, $session ) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 4 102 106
258  
259 106 return $session->{events}->[-1];
260 }
261  
262 sub _handle_filter {
263 37 ▶ my ( $self, $filter ) = @_;
Subroutine _handle_filter: called CC=16 SCAR=27.7
264  
265 37 my %filter;
266 37 @filter{@filter_fields} = split /\|/, $filter, @filter_fields;
267  
268 37 my $suffix = delete $filter{suffix};
269  
270 # For use in error messages
271 37 my $subsystem = $filter{subsystem};
272 37 my $phase = $filter{phase};
273 37 my $session_id = $filter{session};
274 37 ▶ $_ = defined $_ ? "'$_'" : "undef" for $subsystem, $phase, $session_id;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 101 10 111
275  
276 37 my %params;
277 37 my @fields = $self->_filter_fields_for( @filter{qw< subsystem phase >} );
278 32 ▶ @params{@fields} = split /\|/, $suffix, @fields
Branch: 1 branch
BranchTrueFalseTotal
if defined $suffix and @fields 29 3 32
Condition100%3/3
defined $suffix and @fields
!ll&&!rl&&r
2129
MC/DC100%2/2
defined $suffix and @fields
defined $suffix @fields
Truth table100%3/3
A and B
A= defined $suffixB= @fields
ABresult
0X0
100
111
279 if defined $suffix and @fields;
280  
281 32 ▶ my $session = $self->{_sessions}->{ $filter{session} || '' }
Branch: 1 branch
BranchTrueFalseTotal
my $session = $self->{"_sessions"}{$filter{"session"} or ""} or croak("Unknown session $session_id in filter $subsystem|$phase") 2 30 32
Condition100%2/2
$filter{'session'} || ''
l!l
311
MC/DC100%1/1
$filter{'session'} || ''
$filter{'session'}
Truth table100%2/2
A
A= $filter{'session'}
Aresult
11
00
282 or croak("Unknown session $session_id in filter $subsystem|$phase");
283 30 push @{ $session->{events} }, { %filter, %params, request => 'filter' };
284  
285 return $self->_handle_filter_data_line( $params{line}, \%filter, $session )
286 if $filter{subsystem} eq 'smtp-in'
287 30 ▶ and $filter{phase} eq 'data-line';
Branch: 1 branch
BranchTrueFalseTotal
if $filter{"subsystem"} eq "smtp-in" and $filter{"phase"} eq "data-line" 23 7 30
Condition66%2/3
$filter{"subsystem"} eq "smtp-in" and $filter{"phase"} eq "data-line"
!ll&&!rl&&r
0723
MC/DC50%1/2
$filter{"subsystem"} eq "smtp-in" and $filter{"phase"} eq "data-line"
$filter{"subsystem"} eq "smtp-in" $filter{"phase"} eq "data-line"
Truth table66%2/3
A and B
A= $filter{"subsystem"} eq "smtp-in"B= $filter{"phase"} eq "data-line"
ABresult
0X0
100
111
288  
289 7 my @ret;
290 7 ▶ if ( my $cb = $self->_cb_for( filter => @filter{qw< subsystem phase >} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->_cb_for('filter', @filter{'subsystem', 'phase'})) { } 6 1 7
291 {
292 6 @ret = $cb->( $filter{phase}, $session );
293 }
294 else {
295 1 carp("No handler for filter $subsystem|$phase, proceeding");
296 1 @ret = 'proceed';
297 }
298  
299 7 my $decisions = $filter_result_decisions{ $ret[0] };
300 7 ▶ unless ($decisions) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($decisions) 1 6 7
301 1 carp "Unknown return from filter $subsystem|$phase: @ret";
302  
303 1 $ret[0] = 'reject';
304 1 $decisions = $filter_result_decisions{ $ret[0] };
305 }
306  
307 # Pass something as the reason for the rejection
308 7 ▶ push @ret, "550 Nope"
Branch: 1 branch
BranchTrueFalseTotal
if @ret == 1 and ($decisions->[0] || "") eq "error" 3 4 7
Condition100%5/5
@ret == 1 and ($decisions->[0] || "") eq "error"
!ll&&!rl&&r
133
$decisions->[0] || ''
l!l
42
MC/DC100%2/2
@ret == 1 and ($decisions->[0] || "") eq "error"
@ret == 1 $decisions->[0]
Truth table100%3/3
A and B
A= @ret == 1B= $decisions->[0]
ABresult
0X0
100
111
309 if @ret == 1
310 and ( $decisions->[0] || '' ) eq 'error';
311  
312 carp(
313 sprintf "Incorrect params from filter %s|%s, expected %s got %s",
314 $subsystem, $phase,
315 3 join( ' ', map {"'$_'"} 'decision', @$decisions ),
316 3 join( ' ', map {"'$_'"} @ret),
317 7 ▶ ) unless @ret == 1 + @{$decisions};
Branch: 1 branch
BranchTrueFalseTotal
unless @ret == 1 + @{$decisions;} 2 5 7
318  
319 my $response = join '|',
320 'filter-result',
321 7 @filter{qw< session opaque-token >},
322 @ret;
323  
324 7 ▶ STDERR->say("> $response") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 7 7
325 7 $self->{output}->say($response);
326  
327 7 return {%filter};
328 }
329  
330 sub _handle_filter_data_line {
331 23 ▶ my ( $self, $line, $filter, $session ) = @_;
Subroutine _handle_filter_data_line: called CC=11 SCAR=24.0
332 23 ▶ $line //= ''; # avoid uninit warnings
Condition100%2/2
$line //= ""
l!l
176
MC/DC100%1/1
$line //= ""
$line
Truth table100%2/2
A
A= $line
Aresult
11
00
333  
334 23 my @lines;
335 23 ▶ if ( my $cb
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->_cb_for("filter", @{$filter;}{"subsystem", "phase"})) 13 10 23
336 23 = $self->_cb_for( filter => @{$filter}{qw< subsystem phase >} ) )
337 {
338 13 @lines = $cb->( $filter->{phase}, $session, $line );
339 }
340  
341 23 my $message = $session->{messages}->[-1];
342 23 ▶ push @{ $message->{'data-line'} }, $line if $self->{_save_data_lines};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_save_data_lines"} 13 10 23
343  
344 23 ▶ if ( $line eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq ".") 3 20 23
345 my $cb
346 3 = $self->_cb_for( filter => $filter->{subsystem}, 'data-lines' );
347 3 ▶ push @lines, $cb->( 'data-lines', $session, $message->{'data-line'} )
Branch: 1 branch
BranchTrueFalseTotal
if $cb 2 1 3
348 if $cb;
349  
350 # make sure we end the message;
351 3 push @lines, $line;
352 }
353  
354 23 ▶ for ( map { $_ ? split /\n/ : $_ } @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 22 6 28
355 28 ▶ last if $message->{'sent-dot'};
Branch: 1 branch
BranchTrueFalseTotal
if $message->{"sent-dot"} 3 25 28
356  
357 my $response = join '|', 'filter-dataline',
358 25 @{$filter}{qw< session opaque-token >}, $_;
359  
360 25 ▶ STDERR->say("> $response") if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 25 25
361 25 $self->{output}->say($response);
362  
363 25 ▶ $message->{'sent-dot'} = 1 if $_ eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." 3 22 25
364 }
365  
366 23 return $filter;
367 }
368  
369 109 ▶sub _report_fields_for { shift->_fields_for( report => \%report_events, @_ ) }
Subroutine _report_fields_for: called CC=1 SCAR=0.0
370 37 ▶sub _filter_fields_for { shift->_fields_for( filter => \%filter_events, @_ ) }
Subroutine _filter_fields_for: called CC=1 SCAR=0.0
371  
372 sub _fields_for {
373 146 ▶ my ( $self, $type, $map, $subsystem, $item ) = @_;
Subroutine _fields_for: called CC=7 SCAR=19.5
374  
375 146 ▶ if ( $subsystem and $item and my $items = $map->{$subsystem} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subsystem and $item and my $items = $map->{$subsystem}) 140 6 146
Condition100%6/6
$subsystem and $item and my $items = $map->{$subsystem}
!ll&&!rl&&r
42140
$subsystem and $item
!ll&&!rl&&r
31142
MC/DC100%3/3
$subsystem and $item and my $items = $map->{$subsystem}
$subsystem $item my $items = $map->{$subsystem}
Truth table100%4/4
A and B and C
A= $subsystemB= $itemC= my $items = $map->{$subsystem}
ABCresult
0XX0
10X0
1100
1111
376 140 ▶ return @{ $items->{$item} } if $items->{$item};
Branch: 1 branch
BranchTrueFalseTotal
if $items->{$item} 138 2 140
377 }
378  
379 8 ▶ $_ = defined $_ ? "'$_'" : "undef" for $subsystem, $item;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 10 6 16
380 8 croak("Unsupported $type $subsystem|$item");
381 }
382  
383 sub _cb_for {
384 139 ▶ my ( $self, @lookup ) = @_;
Subroutine _cb_for: called CC=4 SCAR=13.9
385  
386 139 my $cb = $self->{on};
387 139 ▶ $cb = $cb->{$_} || {} for @lookup;
Condition100%2/2
$cb->{$_} || {}
l!l
119298
MC/DC100%1/1
$cb->{$_} || {}
$cb->{$_}
Truth table100%2/2
A
A= $cb->{$_}
Aresult
11
00
388  
389 139 ▶ return $cb if ref $cb eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cb eq "CODE" 25 114 139
390  
391 114 return;
392 }
393  
394 5 1;
395  
396 __END__
↑ Summary