blib/lib/OpenSMTPd/Filter.pm

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