lib/Ubic/UA.pm

filter: Statementstmt 29.7% 11 / 37 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 60.0% 3 / 5 Podpod 100% 2 / 2 totaltotal 27.1% 16 / 59 SCAR 36.6
CC
8
Cov
22%
get
56.0
new
6.0
BEGIN
1.0
CRAP 38.9
« blib/lib/Ubic/ServiceLoader/Ext/ini.pm ↑ Summary lib/Ubic/Service/SimpleDaemon.pm »
1 package Ubic::UA;
2 29 $Ubic::UA::VERSION = '1.59';
3 # ABSTRACT: tiny http client
4  
5  
6 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 29 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub new {
11 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
12 0 my %arg = @_;
13  
14 0 my $self = {};
15 0 ▶ $self->{timeout} = $arg{timeout} || 10;
Condition0%0/2
$arg{'timeout'} || 10
l!l
00
MC/DC0%0/1
$arg{'timeout'} || 10
$arg{'timeout'}
Truth table0%0/2
A
A= $arg{'timeout'}
Aresult
11
00
16 0 return bless $self => $class;
17 }
18  
19 sub get {
20 0 ▶ my $self = shift;
Subroutine get: not called CC=7 SCAR=40.3
Pod documented
21 0 my ($url) = @_;
22  
23 0 ▶ unless ($url) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($url) 0 0 0
24 0 return { error => 'Url not specified' };
25 }
26  
27 0 my ($scheme, $authority, $path, $query, undef) = $url
28 =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
29  
30 my $socket = IO::Socket::INET->new(
31 PeerAddr => $authority,
32 Proto => 'tcp',
33 Timeout => $self->{timeout}
34 0 ▶ ) or return {error => $@};
Branch: 1 branch
BranchTrueFalseTotal
my $socket = "IO::Socket::INET"->new("PeerAddr", $authority, "Proto", "tcp", "Timeout", $self->{"timeout"}) or return {"error", $@} 0 0 0
35 0 $socket->autoflush(1);
36 0 ▶ $path .= '?' . $query if $query;
Branch: 1 branch
BranchTrueFalseTotal
if $query 0 0 0
37 0 print $socket "GET $path HTTP/1.0\r\n\r\n";
38 0 my @arr = <$socket>;
39 0 close $socket;
40  
41 0 my $status_line = shift @arr;
42 0 my @headers;
43 0 ▶ while (my $line = shift @arr) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @arr) 0 0 0
44 0 ▶ last if $line eq "\r\n";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "\r\n" 0 0 0
45 0 $line =~ s/\r\n//;
46 0 push @headers, $line;
47 }
48  
49 0 ▶ if ($status_line =~ /^HTTP\/([0-9\.]+)\s+([0-9]{3})\s+(?=([^\r\n]*))?/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status_line =~ m[^HTTP/([0-9\.]+)\s+([0-9]{3})\s+(?=([^\r\n]*))?]i) { } 0 0 0
50 0 my ($ver, $code, $status) = ($1, $2, $3);
51 return {
52 0 ver => $ver,
53 code => $code,
54 status => $status,
55 body => join('', @arr),
56 headers => \@headers,
57 };
58 }
59 else {
60 0 return { error => 'Invalid http response' };
61 }
62 }
63  
64  
65 29 1;
66  
67 __END__
« blib/lib/Ubic/ServiceLoader/Ext/ini.pm ↑ Summary lib/Ubic/Service/SimpleDaemon.pm »