blib/lib/PGP/FindKey.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 50.0% 3 / 6 Conditioncond 44.4% 4 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 3 totaltotal 66.6% 50 / 75 CC 8 SCAR 18.3
CC
8
Cov
74%
_init
11.3
name
2.0
result
2.0
CRAP 6.3
↑ Summary
1 package PGP::FindKey;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $VERSION = '0.02';
7  
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13 1 my ($this, @args) = @_;
14 1 my $class = shift;
15 1 my $self = bless { @_ }, $class;
16 1 return $self->_init(@_);
17 }
18  
19  
20 1 ▶sub _init {
Subroutine _init: called CC=8 SCAR=24.2
21 1 my($self, %params) = @_;;
22  
23 # Caller can set:
24 # \- address: (mandatory)
25 # \- keyserver: (default to 'keyserver.pgp.com')
26 # \- path: (default to '/pks/lookup')
27 # \- command: (default to '?op=index&search=')
28
29 1 ▶ return undef unless exists($params{address});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"address"} 0 1 1
30 1 ▶ $self->{keyserver} ||= 'keyserver.pgp.com';
Condition50%1/2
$self->{"keyserver"} ||= "keyserver.pgp.com"
l!l
10
MC/DC0%0/1
$self->{"keyserver"} ||= "keyserver.pgp.com"
$self->{"keyserver"}
Truth table50%1/2
A
A= $self->{"keyserver"}
Aresult
11
00
31 1 ▶ $self->{path} ||= '/pks/lookup';
Condition50%1/2
$self->{"path"} ||= "/pks/lookup"
l!l
01
MC/DC0%0/1
$self->{"path"} ||= "/pks/lookup"
$self->{"path"}
Truth table50%1/2
A
A= $self->{"path"}
Aresult
11
00
32 1 ▶ $self->{command} ||= '?op=index&search=';
Condition50%1/2
$self->{"command"} ||= "?op=index&search="
l!l
01
MC/DC0%0/1
$self->{"command"} ||= "?op=index&search="
$self->{"command"}
Truth table50%1/2
A
A= $self->{"command"}
Aresult
11
00
33 1 ▶ $self->{address} ||= uri_escape($params{address});
Condition33%1/3
$self->{"address"} ||= uri_escape($params{"address"})
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"address"} ||= uri_escape($params{"address"})
$self->{"address"} uri_escape($params{"address"})
Truth table33%1/3
A ||= B
A= $self->{"address"}B= uri_escape($params{"address"})
ABresult
1X1
011
000
34  
35 1 my $query = "http://" . $self->{keyserver} . $self->{path} . $self->{command} . $self->{address};
36  
37 1 my $ua = LWP::UserAgent->new();
38
39 # Check for *_proxy env vars. Use them if they're there.
40 1 $ua->env_proxy();
41
42 # Get the page.
43  
44 1 my $req = new HTTP::Request('GET' => $query);
45 1 my $res = $ua->request($req);
46 1 ▶ unless($res->is_success){
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->is_success) 0 1 1
47 0 warn(__PACKAGE__ . ":" . $res->status_line);
48 0 return undef;
49 }
50 1 my $page = $res->content;
51
52 # Parse the response page. $count contains number of re matches.
53 # An example of the html response is:
54 #
55 # pub 1024/<a href="/pks/lookup?op=get&search=0x7C2F31DF">7C2F31DF\
56 # </a> 2001/08/28 Chris J. Ball &lt;<a href="/pks/lookup?op=get&search\
57 # =0x7C2F31DF">chris@void.printf.net</a>&gt;
58  
59 1 my $count =()= $page =~ m!pub \d{4}/<a.*?href.*?>(.{8})</a> \d{4}/\d{2}/\d{2} (.*) &lt!g;
60  
61 # We must only have two matches; one for keyid, one for name. Zero
62 # matches signifies a missed search, and more than two would signify
63 # multiple matches. The reason for giving up and returning undef in
64 # the latter case is explained POD-wards.
65
66 1 ▶ return undef unless $count == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $count == 2 1 0 1
67 0 $self->{_result} = $1;
68 0 $self->{_name} = $2;
69 0 return $self;
70 }
71  
72 0 ▶sub name { return $_[0]->{_name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
73 0 ▶sub result { return $_[0]->{_result} }
Subroutine result: not called CC=1 SCAR=6.9
Pod undocumented
74  
75 1 1;
76 __END__
↑ Summary