blib/lib/POE/Filter/DNS/TCP.pm

filter: Statementstmt 94.5% 52 / 55 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 91.6% 11 / 12 Podpod 100% 5 / 5 totaltotal 88.7% 79 / 89 CC 9 SCAR 10.0
CC
9
Cov
89%
get_one
5.2
_decoder
3.0
put
3.0
CRAP 2.7
↑ Summary
1 package POE::Filter::DNS::TCP;
2 2 $POE::Filter::DNS::TCP::VERSION = '0.06';
3 #ABSTRACT: A POE Filter to handle DNS over TCP connections
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Net::DNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Net::DNS::Packet;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base 'POE::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub FRAMING_BUFFER () { 0 }
15 sub EXPECTED_SIZE () { 1 }
16 sub INT16SZ () { 2 }
17  
18 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
19 1 my $class = shift;
20 1 my $self = bless [
21 '', # FRAMING_BUFFER
22 undef, # EXPECTED_SIZE
23 ], $class;
24 1 return $self;
25 }
26  
27 2 ▶sub get_one_start {
Subroutine get_one_start: called CC=1 SCAR=0.0
Pod documented
28 2 my ($self, $stream) = @_;
29 2 $self->[FRAMING_BUFFER] .= join '', @$stream;
30 }
31  
32 4 ▶sub get_one {
Subroutine get_one: called CC=5 SCAR=16.6
Pod documented
33 4 my $self = shift;
34  
35 4 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1] or defined($self->[1] = _decoder(\$self->[0]))) 2 2 4
Condition66%2/3
defined $self->[1] or defined($self->[1] = _decoder(\$self->[0]))
l!l&&r!l&&!r
022
MC/DC50%1/2
defined $self->[1] or defined($self->[1] = _decoder(\$self->[0]))
defined $self->[1] defined($self->[1] = _decoder(\$self->[0]))
Truth table66%2/3
A or B
A= defined $self->[1]B= defined($self->[1] = _decoder(\$self->[0]))
ABresult
1X1
011
000
36 defined($self->[EXPECTED_SIZE]) ||
37 defined(
38 $self->[EXPECTED_SIZE] = _decoder(\$self->[FRAMING_BUFFER])
39 )
40 ) {
41 2 ▶ return [ ] if length($self->[FRAMING_BUFFER]) < $self->[EXPECTED_SIZE];
Branch: 1 branch
BranchTrueFalseTotal
if length $self->[0] < $self->[1] 0 2 2
42  
43 # Four-arg substr() would be better here, but it's not compatible
44 # with Perl as far back as we support.
45 2 my $block = substr($self->[FRAMING_BUFFER], 0, $self->[EXPECTED_SIZE]);
46 2 substr($self->[FRAMING_BUFFER], 0, $self->[EXPECTED_SIZE]) = '';
47 2 $self->[EXPECTED_SIZE] = undef;
48  
49 2 ▶ if ( my $packet = Net::DNS::Packet->new( \$block ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $packet = "Net::DNS::Packet"->new(\$block)) 2 0 2
50 2 return [ $packet ];
51 }
52 0 warn "Could not parse DNS packet\n";
53 }
54  
55 2 return [];
56 }
57  
58 4 ▶sub _decoder {
Subroutine _decoder: called CC=3 SCAR=11.0
59 4 my $data = shift;
60 4 my $buf = substr $$data, 0, INT16SZ;
61 4 ▶ return unless length $buf;
Branch: 1 branch
BranchTrueFalseTotal
unless length $buf 2 2 4
62 2 my ($len) = unpack 'n', $buf;
63 2 ▶ return unless $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $len 0 2 2
64 2 substr $$data, 0, INT16SZ, '';
65 2 return $len;
66 }
67  
68 0 ▶sub get_pending {
Subroutine get_pending: not called CC=1 SCAR=6.9
Pod documented
69 0 my $self = shift;
70 0 return $self->[FRAMING_BUFFER];
71 }
72  
73 2 ▶sub put {
Subroutine put: called CC=3 SCAR=11.0
Pod documented
74 2 my $self = shift;
75 2 my $packets = shift;
76 2 my @blocks;
77 2 foreach my $packet (@$packets) {
78 2 ▶ next unless eval { $packet->isa('Net::DNS::Packet'); };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $packet->isa("Net::DNS::Packet") } } 0 2 2
79 2 $packet->{buffer} = '';
80 2 my $packet_data = $packet->data;
81 2 my $lenmsg = pack( 'n', length $packet_data );
82 2 push @blocks, $lenmsg . $packet_data;
83 }
84 2 return \@blocks;
85 }
86  
87 2 q[You know like, in'it];
88  
89 __END__
↑ Summary