blib/lib/WWW/HKP.pm

filter: Statementstmt 56.5% 52 / 92 Branchbran 51.9% 27 / 52 Conditioncond 43.9% 29 / 66 MC/DCmcdc 12.5% 4 / 32 Subroutinesub 56.2% 9 / 16 Podpod 100% 4 / 4 totaltotal 47.7% 125 / 262 SCAR 58.9
CC
52
Cov
51%
query
72.0
_parse_mr
41.6
_get
30.0
CRAP 361.8
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package WWW::HKP;
4 # ABSTRACT: Interface to HTTP Keyserver Protocol (HKP)
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use LWP::UserAgent 6.05;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use URI 1.60;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use URI::Escape 3.31;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = '0.04'; # VERSION
13  
14  
15 sub new($;%) {
16 2 ▶ my ($class, %options) = @_;
Subroutine new: called CC=4 SCAR=14.6
Pod documented
17
18 2 my $uri = URI->new('http:');
19 2 ▶ $uri->host($options{host} || 'localhost');
Condition50%1/2
$options{'host'} || 'localhost'
l!l
02
MC/DC0%0/1
$options{'host'} || 'localhost'
$options{'host'}
Truth table50%1/2
A
A= $options{'host'}
Aresult
11
00
20 2 ▶ $uri->port($options{port} || 11371);
Condition50%1/2
$options{'port'} || 11371
l!l
02
MC/DC0%0/1
$options{'port'} || 11371
$options{'port'}
Truth table50%1/2
A
A= $options{'port'}
Aresult
11
00
21
22 2 my $ua = LWP::UserAgent->new;
23 2 $ua->agent(__PACKAGE__.'/'.$VERSION);
24
25 2 my $self = {
26 ua => $ua,
27 uri => $uri,
28 };
29
30 2 ▶ return bless $self => (ref $class || $class);
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
31 }
32  
33 0 ▶sub _ua($) { shift->{ua} }
Subroutine _ua: not called CC=1 SCAR=6.9
34 0 ▶sub _uri($) { shift->{uri} }
Subroutine _uri: not called CC=1 SCAR=6.9
35  
36 sub _get($$) {
37 0 ▶ my ($self, %query) = @_;
Subroutine _get: not called CC=5 SCAR=34.0
38 0 $self->{error} = undef;
39 0 $self->_uri->path('/pks/lookup');
40 0 $self->_uri->query_form(%query);
41 0 my $response = $self->_ua->get($self->_uri);
42 0 ▶ if (defined $response and ref $response and $response->isa('HTTP::Response') and $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response and ref $response and $response->isa('HTTP::Response') and $response->is_success) { } 0 0 0
Condition0%0/9
defined $response and ref $response and $response->isa("HTTP::Response") and $response->is_success
!ll&&!rl&&r
000
defined $response and ref $response and $response->isa("HTTP::Response")
!ll&&!rl&&r
000
defined $response and ref $response
!ll&&!rl&&r
000
MC/DC0%0/4
defined $response and ref $response and $response->isa("HTTP::Response") and $response->is_success
defined $response ref $response $response->isa("HTTP::Response") $response->is_success
Truth table0%0/5
A and B and C and D
A= defined $responseB= ref $responseC= $response->isa("HTTP::Response")D= $response->is_success
ABCDresult
0XXX0
10XX0
110X0
11100
11111
43 0 return $response->decoded_content;
44 } else {
45 0 $self->{error} = $response->status_line;
46 0 return undef;
47 }
48 }
49  
50 sub _post($%) {
51 0 ▶ my ($self, %query) = @_;
Subroutine _post: not called CC=5 SCAR=34.0
52 0 $self->{error} = undef;
53 0 $self->_uri->path('/pks/lookup');
54 0 my $response = $self->_ua->post($self->_uri, \%query);
55 0 ▶ if (defined $response and ref $response and $response->isa('HTTP::Response') and $response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response and ref $response and $response->isa('HTTP::Response') and $response->is_success) { } 0 0 0
Condition0%0/9
defined $response and ref $response and $response->isa("HTTP::Response") and $response->is_success
!ll&&!rl&&r
000
defined $response and ref $response and $response->isa("HTTP::Response")
!ll&&!rl&&r
000
defined $response and ref $response
!ll&&!rl&&r
000
MC/DC0%0/4
defined $response and ref $response and $response->isa("HTTP::Response") and $response->is_success
defined $response ref $response $response->isa("HTTP::Response") $response->is_success
Truth table0%0/5
A and B and C and D
A= defined $responseB= ref $responseC= $response->isa("HTTP::Response")D= $response->is_success
ABCDresult
0XXX0
10XX0
110X0
11100
11111
56 0 return $response->decoded_content;
57 } else {
58 0 $self->{error} = $response->status_line;
59 0 return undef;
60 }
61  
62 }
63  
64 sub _parse_mr($$$) {
65 3 ▶ my ($self, $lines, $filter_ok) = @_;
Subroutine _parse_mr: called CC=32 SCAR=37.3
66 3 my $keys = {};
67 3 my $key;
68 3 my ($keyc, $keyn) = (0, 0);
69 3 foreach my $line (split /\r?\n/ => $lines) {
70 10 ▶ if ($line =~ /^info:(\d+):(\d+)$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($line =~ /^info:(\d+):(\d+)$/) { } 3 7 10
elsif ($line =~ /^pub:([0-9a-f]{8,16}):(\d*):(\d*):(\d*):(\d*):([der]*)$/i) { } 3 4 7
elsif ($line =~ /^uid:([^:]*):(\d*):(\d*):([der]*)$/i) { } 4 0 4
71 3 ▶ croak "unsupported hkp version: v$1" unless $1 == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 == 1 0 3 3
72 3 $keyc = $2;
73 } elsif ($line =~ /^pub:([0-9a-f]{8,16}):(\d*):(\d*):(\d*):(\d*):([der]*)$/i) {
74 3 $key = $1;
75 3 $keyn++;
76 3 my ($algo, $keylen, $created, $expires, $flags, $ok) = ($2, $3, $4, $5, $6, undef);
77 3 ▶ $ok = ((($created and $created > time) or ($expires and $expires < time) or (length $flags)) ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$created && $created > time || $expires && $expires < time || length $flags ? : 1 2 3
Condition58%7/12
$created and $created > time or $expires and $expires < time or length $flags
l!l&&r!l&&!r
102
$created and $created > time or $expires and $expires < time
l!l&&r!l&&!r
012
$created and $created > time
!ll&&!rl&&r
030
$expires and $expires < time
!ll&&!rl&&r
021
MC/DC20%1/5
$created and $created > time or $expires and $expires < time or length $flags
$created $created > time $expires $expires < time length $flags
Truth table18%2/11
A and B or C and D or E
A= $createdB= $created > timeC= $expiresD= $expires < timeE= length $flags
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
78 3 ▶ if ($filter_ok and !$ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filter_ok and not $ok) 0 3 3
Condition66%2/3
$filter_ok and not $ok
!ll&&!rl&&r
120
MC/DC0%0/2
$filter_ok and not $ok
$filter_ok not $ok
Truth table66%2/3
A and not(B)
A= $filter_okB= not $ok
ABresult
0X0
100
111
79 0 $key = undef;
80 0 next;
81 }
82 3 ▶ $keys->{$key} = {
Branch: 3 branches
BranchTrueFalseTotal
$flags =~ /r/ ? : 1 2 3
$flags =~ /e/ ? : 1 2 3
$flags =~ /d/ ? : 1 2 3
Condition50%2/4
$created || undef
l!l
30
$expires || undef
l!l
30
MC/DC0%0/1
$created || undef
$created
MC/DC0%0/1
$expires || undef
$expires
Truth table50%1/2
A
A= $created
Aresult
11
00
Truth table50%1/2
A
A= $expires
Aresult
11
00
83 algo => $algo,
84 keylen => $keylen,
85 created => $created || undef,
86 expires => $expires || undef,
87 revoked => ($flags =~ /r/ ? 1 : 0),
88 expired => ($flags =~ /e/ ? 1 : 0),
89 deleted => ($flags =~ /d/ ? 1 : 0),
90 ok => $ok,
91 uids => []
92 };
93 } elsif ($line =~ /^uid:([^:]*):(\d*):(\d*):([der]*)$/i) {
94 4 ▶ next unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 4 4
95 4 my ($uid, $created, $expires, $flags, $ok) = ($1, $2, $3, $4, undef);
96 4 ▶ $ok = ((($created and $created > time) or ($expires and $expires < time) or (length $flags)) ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$created && $created > time || $expires && $expires < time || length $flags ? : 3 1 4
Condition83%10/12
$created and $created > time or $expires and $expires < time or length $flags
l!l&&r!l&&!r
211
$created and $created > time or $expires and $expires < time
l!l&&r!l&&!r
022
$created and $created > time
!ll&&!rl&&r
130
$expires and $expires < time
!ll&&!rl&&r
112
MC/DC20%1/5
$created and $created > time or $expires and $expires < time or length $flags
$created $created > time $expires $expires < time length $flags
Truth table27%3/11
A and B or C and D or E
A= $createdB= $created > timeC= $expiresD= $expires < timeE= length $flags
ABCDEresult
11XXX1
0X11X1
1011X1
0X0X11
0X1011
100X11
101011
0X0X00
0X1000
100X00
101000
97 4 ▶ next if $filter_ok and !$ok;
Branch: 1 branch
BranchTrueFalseTotal
if $filter_ok and not $ok 2 2 4
Condition100%3/3
$filter_ok and not $ok
!ll&&!rl&&r
112
MC/DC100%2/2
$filter_ok and not $ok
$filter_ok not $ok
Truth table100%3/3
A and not(B)
A= $filter_okB= not $ok
ABresult
0X0
100
111
98 2 ▶ push @{ $keys->{$key}->{uids} } => {
Branch: 3 branches
BranchTrueFalseTotal
$flags =~ /r/ ? : 1 1 2
$flags =~ /e/ ? : 1 1 2
$flags =~ /d/ ? : 1 1 2
Condition50%2/4
$created || undef
l!l
20
$expires || undef
l!l
20
MC/DC0%0/1
$created || undef
$created
MC/DC0%0/1
$expires || undef
$expires
Truth table50%1/2
A
A= $created
Aresult
11
00
Truth table50%1/2
A
A= $expires
Aresult
11
00
99 uid => uri_unescape($uid),
100 created => $created || undef,
101 expires => $expires || undef,
102 revoked => ($flags =~ /r/ ? 1 : 0),
103 expired => ($flags =~ /e/ ? 1 : 0),
104 deleted => ($flags =~ /d/ ? 1 : 0),
105 ok => $ok
106 };
107 } else {
108 0 carp "unknown line: $line";
109 }
110 }
111 3 ▶ carp "server said there where $keyc keys, but $keyn keys parsed" unless $keyc == $keyn;
Branch: 1 branch
BranchTrueFalseTotal
unless $keyc == $keyn 0 3 3
112 3 return $keys;
113 }
114  
115  
116 sub query($$$;%) {
117 0 ▶ my ($self, $type, $search, %options) = @_;
Subroutine query: not called CC=8 SCAR=42.8
Pod documented
118  
119  
120 0 ▶ if ($type eq 'index') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'index') { } 0 0 0
elsif ($type eq 'get') { } 0 0 0
121 0 my @options = qw(mr);
122 0 ▶ push @options => 'exact' if $options{exact};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"exact"} 0 0 0
123 0 my $message = $self->_get(op => 'index', options => join(',' => @options), search => $search);
124 0 ▶ return undef unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
125 0 ▶ return $self->_parse_mr($message, $options{filter_ok} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$options{'filter_ok'} ? : 0 0 0
126 }
127  
128  
129 elsif ($type eq 'get') {
130 0 ▶ if ($search !~ /^0x/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($search =~ /^0x/) 0 0 0
131 0 $search = '0x'.$search;
132 }
133 0 my $message = $self->_get(op => 'get', options => 'exact', search => $search);
134 0 ▶ return undef unless defined $message;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 0 0 0
135 0 return $message;
136 }
137  
138  
139 else {
140 0 confess "unknown query type '$type'";
141 }
142 }
143  
144  
145 sub submit($@) {
146 0 ▶ my ($self, @keys) = @_;
Subroutine submit: not called CC=3 SCAR=24.8
Pod documented
147 0 my $status = $self->_post(map {( keytext => $_ )} @keys);
148 0 ▶ return (defined $status and $status ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$status ? : 0 0 0
Condition0%0/3
defined $status && ($status ? 1 : 0)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $status && ($status ? 1 : 0)
defined $status ($status ? 1 : 0)
Truth table0%0/3
A && B
A= defined $statusB= ($status ? 1 : 0)
ABresult
0X0
100
111
149 }
150  
151  
152 0 ▶sub error($) { shift->{error} }
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
153  
154 2 1;
155  
156 __END__
↑ Summary