blib/lib/WebService/OkiLab/ExtractPlace.pm

filter: Statementstmt 32.2% 20 / 62 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 46.1% 6 / 13 Podpod 100% 7 / 7 totaltotal 30.2% 33 / 109 CC 13 SCAR 41.0
CC
13
Cov
23%
extract
132.0
param
12.0
new
2.0
CRAP 60.2
↑ Summary
1 package WebService::OkiLab::ExtractPlace;
2
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 our $VERSION = 0.02;
8
9 2 ▶use HTTP::Request::Common qw(GET POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
14 0 my $class = shift;
15 0 my $self = bless {}, $class;
16 0 $self->url('http://okilab.jp/project/location/api/v1/extract_place/');
17 0 my $ua = LWP::UserAgent->new();
18 0 $ua->env_proxy();
19 0 $self->ua($ua);
20 0 return $self;
21 }
22
23 0 ▶sub param {
Subroutine param: not called CC=3 SCAR=24.8
Pod documented
24 0 my $self = shift;
25 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
26 0 my $key = shift;
27 0 ▶ $self->{"_$key"} = shift if (@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
28 0 return $self->{"_$key"};
29 } else {
30 0 my @keys = sort map { substr($_, 1) } grep { /^_/ } keys(%{$self});
31 0 return @keys;
32 }
33 }
34
35 0 ▶sub ua { my $self = shift; return $self->param('ua', @_); }
Subroutine ua: not called CC=1 SCAR=6.9
Pod documented
36 0 ▶sub url { my $self = shift; return $self->param('url', @_); }
Subroutine url: not called CC=1 SCAR=6.9
Pod documented
37 0 ▶sub res { my $self = shift; return $self->param('res', @_); }
Subroutine res: not called CC=1 SCAR=6.9
Pod documented
38 0 ▶sub req { my $self = shift; return $self->param('req', @_); }
Subroutine req: not called CC=1 SCAR=6.9
Pod documented
39
40 0 ▶sub extract {
Subroutine extract: not called CC=11 SCAR=48.8
Pod documented
41 0 my $self = shift;
42 0 my $text = shift;
43 0 my $ua = $self->ua();
44 0 my $url = URI->new($self->url());
45 0 ▶ return $self->error("Can't load LWP::UserAgent object.") if (not UNIVERSAL::isa($ua, 'LWP::UserAgent'));
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($ua, "LWP::UserAgent") 0 0 0
46 0 ▶ return $self->error("Web service url is invalid. ($url)") if ($url->scheme ne 'http');
Branch: 1 branch
BranchTrueFalseTotal
if $url->scheme ne "http" 0 0 0
47 0 ▶ return $self->error("Text is empty.") if ($text !~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\S/ 0 0 0
48 # create HTTP::Response
49 0 ▶ my $method = uc($self->param('method')) || 'POST';
Condition0%0/2
uc $self->param('method') || 'POST'
l!l
00
MC/DC0%0/1
uc $self->param('method') || 'POST'
uc $self->param('method')
Truth table0%0/2
A
A= uc $self->param('method')
Aresult
11
00
50 0 ▶ $url->query_form('text' => $text) if ($method eq 'GET');
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "GET" 0 0 0
51 0 ▶ my $req = ($method eq 'GET') ? GET($url) : POST($url, ['text' => $text]);
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 0 0 0
52 # do reqeust
53 0 $self->req($req);
54 0 my $res = $ua->request($req);
55 0 ▶ $self->res($res) || return $self->error('Response is empty.');
Branch: 1 branch
BranchTrueFalseTotal
$self->res($res) or return $self->error("Response is empty.") 0 0 0
56 0 ▶ $res->is_success || return $self->error(sprintf('Request failed. (%s)', $res->status_line));
Branch: 1 branch
BranchTrueFalseTotal
$res->is_success or return $self->error(sprintf("Request failed. (%s)", $res->status_line)) 0 0 0
57 # parse result
58 0 ▶ my $json = $res->content() || return $self->error('Response content is empty.');
Condition0%0/2
$res->content || (return $self->error('Response content is empty.'))
l!l
00
MC/DC0%0/1
$res->content || (return $self->error('Response content is empty.'))
$res->content
Truth table0%0/2
A
A= $res->content
Aresult
11
00
59 0 ▶ my $result = jsonToObj($json) || return $self->error("Can't parse response content.");
Condition0%0/2
jsonToObj($json) || (return $self->error(q[Can't parse response content.]))
l!l
00
MC/DC0%0/1
jsonToObj($json) || (return $self->error(q[Can't parse response content.]))
jsonToObj($json)
Truth table0%0/2
A
A= jsonToObj($json)
Aresult
11
00
60 0 return $result;
61 }
62
63 2 1;
64 __END__
↑ Summary