| 1 | package Gcis::Client; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Mojo::Log; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use YAML::XS qw/LoadFile/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Path::Class qw/file/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Time::HiRes qw/sleep/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use v5.14; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | has url => 'http://localhost:3000'; | |||||||||||||||||||||||||||
| 15 | 3 | has 'key'; | |||||||||||||||||||||||||||
| 16 | 3 | has 'error'; | |||||||||||||||||||||||||||
| 17 | 3 | has 'delay' => $ENV{GCIS_API_DELAY}; | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | has ua => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 19 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 20 | 0 | state $ua; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | return $ua if $ua; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | $ua = Mojo::UserAgent->new(); | |||||||||||||||||||||||||||
| 23 | $ua->on( | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | start => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 25 | 0 | my ($ua, $tx) = @_; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | $tx->req->headers->header($c->auth_hdr) if $c->auth_hdr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | $tx->req->headers->header(Accept => $c->accept); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | ); | |||||||||||||||||||||||||||
| 30 | 0 | $ua->max_redirects(5); | |||||||||||||||||||||||||||
| 31 | 0 | $ua; | |||||||||||||||||||||||||||
| 32 | 3 | }; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | has logger => sub { state $log ||= Mojo::Log->new(); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
state $log ||= "Mojo::Log"->new
MC/DC0%0/2
state $log ||= "Mojo::Log"->new
state $log
"Mojo::Log"->new
Truth table0%0/3
A ||= B
A= state $logB= "Mojo::Log"->new
| |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | has json => sub { state $json ||= JSON::XS->new(); }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=14.0
Condition0%0/3
state $json ||= "JSON::XS"->new
MC/DC0%0/2
state $json ||= "JSON::XS"->new
state $json
"JSON::XS"->new
Truth table0%0/3
A ||= B
A= state $jsonB= "JSON::XS"->new
| |||||||||||||||||||||||||||||
| 35 | 3 | has accept => "application/json"; | |||||||||||||||||||||||||||
| 36 | 3 | has 'tx'; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub auth_hdr { ($a = shift->key) ? ("Authorization" => "Basic $a") : () } | ||||||||||||||||||||||||||
|
Subroutine
auth_hdr: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $path = shift or die "missing path"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | my $params = shift; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (defined($s->delay)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | $s->logger->debug("sleeping for ".$s->delay.'s'); | |||||||||||||||||||||||||||
| 46 | 0 | sleep $s->delay; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | my $url; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ($params) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $url = Mojo::URL->new($s->url); | |||||||||||||||||||||||||||
| 51 | 0 | $url->path($path); | |||||||||||||||||||||||||||
| 52 | 0 | $url->query(%$params); | |||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | 0 | $url = Mojo::URL->new($s->url.$path); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | my $tx = $s->ua->get($url); | |||||||||||||||||||||||||||
| 57 | 0 | $s->tx($tx); | |||||||||||||||||||||||||||
| 58 | 0 | my $res = $tx->success; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | unless ($res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($tx->res->code && $tx->res->code == 404) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tx->res->code and $tx->res->code == 404
MC/DC0%0/2
$tx->res->code and $tx->res->code == 404
$tx->res->code
$tx->res->code == 404
Truth table0%0/3
A and B
A= $tx->res->codeB= $tx->res->code == 404
| |||||||||||||||||||||||||||||
| 61 | # $s->logger->debug("not found : $path"); | ||||||||||||||||||||||||||||
| 62 | 0 | $s->error("not found : $path"); | |||||||||||||||||||||||||||
| 63 | 0 | return; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | $s->error($tx->error->{message}); | |||||||||||||||||||||||||||
| 66 | 0 | $s->logger->error($tx->error->{message}); | |||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $json = $res->json or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $s->logger->debug("no json from $path : ".$res->to_string); | |||||||||||||||||||||||||||
| 71 | 0 | $s->error("No JSON returned from $path : ".$res->to_string); | |||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return wantarray && ref($json) eq 'ARRAY' ? @$json : $json; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
wantarray and ref $json eq "ARRAY"
MC/DC0%0/2
wantarray and ref $json eq "ARRAY"
wantarray
ref $json eq "ARRAY"
Truth table0%0/3
A and B
A= wantarrayB= ref $json eq "ARRAY"
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | my $path = shift or Carp::confess "missing path"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 81 | 0 | my $tx = $s->ua->post($s->url."$path" => json => $data ); | |||||||||||||||||||||||||||
| 82 | 0 | $s->tx($tx); | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $res = $tx->success or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $s->logger->error("got an error $path : ".Dumper($tx->error->{message}).$tx->res->body); | |||||||||||||||||||||||||||
| 85 | 0 | return; | |||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return unless $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $json = $res->json or return $res->body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | return $res->json; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub delete { | ||||||||||||||||||||||||||
|
Subroutine
delete: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 94 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 95 | 0 | my $payload = shift; | |||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $tx = $s->ua->delete($s->url."$path", ( $payload ? (json => $payload) : () ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | $s->tx($tx); | |||||||||||||||||||||||||||
| 98 | 0 | my $res = $tx->success; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | unless ($res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($tx->res->code && $tx->res->code == 404) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tx->res->code and $tx->res->code == 404
MC/DC0%0/2
$tx->res->code and $tx->res->code == 404
$tx->res->code
$tx->res->code == 404
Truth table0%0/3
A and B
A= $tx->res->codeB= $tx->res->code == 404
| |||||||||||||||||||||||||||||
| 101 | 0 | $s->error("not found : $path"); | |||||||||||||||||||||||||||
| 102 | 0 | return; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | $s->error($tx->error->{message}); | |||||||||||||||||||||||||||
| 105 | 0 | $s->logger->error($tx->error->{message}); | |||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||
| 108 | 0 | return $res->body; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub put_file { | ||||||||||||||||||||||||||
|
Subroutine
put_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 113 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 114 | 0 | my $file = shift; | |||||||||||||||||||||||||||
| 115 | 0 | my $data = file($file)->slurp; | |||||||||||||||||||||||||||
| 116 | 0 | my $tx = $s->ua->put($s->url."$path" => $data ); | |||||||||||||||||||||||||||
| 117 | 0 | $s->tx($tx); | |||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $res = $tx->success or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $s->error(join "\n",$tx->error->{message},$tx->res->body); | |||||||||||||||||||||||||||
| 120 | 0 | $s->logger->error($path." : ".$tx->error->{message}); | |||||||||||||||||||||||||||
| 121 | 0 | $s->logger->error($tx->res->body); | |||||||||||||||||||||||||||
| 122 | 0 | return; | |||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return unless $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $json = $res->json or return $res->body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | return $res->json; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub add_file_url { | ||||||||||||||||||||||||||
|
Subroutine
add_file_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 131 | 0 | my $gcid = shift; | |||||||||||||||||||||||||||
| 132 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 133 | 0 | my $path = $gcid; | |||||||||||||||||||||||||||
| 134 | 0 | $path =~ s[/([^/]+)$][/files/$1]; | |||||||||||||||||||||||||||
| 135 | 0 | $s->post($path => $args); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub post_quiet { | ||||||||||||||||||||||||||
|
Subroutine
post_quiet: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 140 | 0 | my $path = shift; | |||||||||||||||||||||||||||
| 141 | 0 | my $data = shift; | |||||||||||||||||||||||||||
| 142 | 0 | my $tx = $s->ua->post($s->url."$path" => json => $data ); | |||||||||||||||||||||||||||
| 143 | 0 | $s->tx($tx); | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | my $res = $tx->success or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $s->logger->error("$path : ".$tx->error.$tx->res->body) unless $tx->res->code == 404; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | return; | |||||||||||||||||||||||||||
| 147 | }; | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return unless $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $json = $res->json or return $res->body; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | return $res->json; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub find_credentials { | ||||||||||||||||||||||||||
|
Subroutine
find_credentials: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 155 | 0 | my $home = $ENV{HOME}; | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | die "need url to find credentials" unless $s->url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | my $conf_file = "$home/etc/Gcis.conf"; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | -e $conf_file or die "Missing $conf_file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 0 | my $conf = LoadFile($conf_file); | |||||||||||||||||||||||||||
| 160 | 0 | my @found = grep { $_->{url} eq $s->url } @$conf; | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | die "Multiple matches for ".$s->url." in $conf_file." if @found > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | die "No matches for ".$s->url." in $conf_file." if @found < 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $key = $found[0]->{key} or die "no key for ".$s->url." in $conf_file"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | $s->logger->info("Loaded configuration from $conf_file"); | |||||||||||||||||||||||||||
| 165 | 0 | $s->key($key); | |||||||||||||||||||||||||||
| 166 | 0 | return $s; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $got = $c->get('/login') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $c->get('/login')->{login} eq 'ok' or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | return $c; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | sub use_env { | ||||||||||||||||||||||||||
|
Subroutine
use_env: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $url = $ENV{GCIS_API_URL} or die "please set GCIS_API_URL"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | $c->url($url); | |||||||||||||||||||||||||||
| 180 | 0 | return $c; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub get_chapter_map { | ||||||||||||||||||||||||||
|
Subroutine
get_chapter_map: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 184 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $report = shift or die "no report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $all = $c->get("/report/$report/chapter?all=1") or die $c->url.' : '.$c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my %map = map { $_->{number} // $_->{identifier} => $_->{identifier} } @$all; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_->{"number"} // $_->{"identifier"}
MC/DC0%0/2
$_->{"number"} // $_->{"identifier"}
$_->{"number"}
$_->{"identifier"}
Truth table0%0/3
A // B
A= $_->{"number"}B= $_->{"identifier"}
| |||||||||||||||||||||||||||||
| 188 | 0 | ▶ | return wantarray ? %map : \%map; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub tables { | ||||||||||||||||||||||||||
|
Subroutine
tables: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 192 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 193 | 0 | my %a = @_; | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $report = $a{report} or die "no report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if (my $chapter_number = $a{chapter_number}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | $c->{_chapter_map}->{$report} //= $c->get_chapter_map($report); | ||||||||||||||||||||||||||
|
Condition0%0/3
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
MC/DC0%0/2
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
$c->{"_chapter_map"}{$report}
$c->get_chapter_map($report)
Truth table0%0/3
A //= B
A= $c->{"_chapter_map"}{$report}B= $c->get_chapter_map($report)
| |||||||||||||||||||||||||||||
| 197 | 0 | $a{chapter} = $c->{_chapter_map}->{$report}->{$chapter_number}; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 0 | my $tables; | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | if (my $chapter = $a{chapter}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $tables = $c->get("/report/$report/chapter/$chapter/table?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | } else { | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $tables = $c->get("/report/$report/table?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | return wantarray ? @$tables : $tables; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub figures { | ||||||||||||||||||||||||||
|
Subroutine
figures: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 209 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 210 | 0 | my %a = @_; | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | my $report = $a{report} or die "no report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if (my $chapter_number = $a{chapter_number}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $c->{_chapter_map}->{$report} //= $c->get_chapter_map($report); | ||||||||||||||||||||||||||
|
Condition0%0/3
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
MC/DC0%0/2
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
$c->{"_chapter_map"}{$report}
$c->get_chapter_map($report)
Truth table0%0/3
A //= B
A= $c->{"_chapter_map"}{$report}B= $c->get_chapter_map($report)
| |||||||||||||||||||||||||||||
| 214 | 0 | $a{chapter} = $c->{_chapter_map}->{$report}->{$chapter_number}; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 0 | my $figures; | |||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (my $chapter = $a{chapter}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $figures = $c->get("/report/$report/chapter/$chapter/figure?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $figures = $c->get("/report/$report/figure?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | return wantarray ? @$figures : $figures; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub findings { | ||||||||||||||||||||||||||
|
Subroutine
findings: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 226 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 227 | 0 | my %a = @_; | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | my $report = $a{report} or die "no report"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (my $chapter_number = $a{chapter_number}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | $c->{_chapter_map}->{$report} //= $c->get_chapter_map($report); | ||||||||||||||||||||||||||
|
Condition0%0/3
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
MC/DC0%0/2
$c->{"_chapter_map"}{$report} //= $c->get_chapter_map($report)
$c->{"_chapter_map"}{$report}
$c->get_chapter_map($report)
Truth table0%0/3
A //= B
A= $c->{"_chapter_map"}{$report}B= $c->get_chapter_map($report)
| |||||||||||||||||||||||||||||
| 231 | 0 | $a{chapter} = $c->{_chapter_map}->{$report}->{$chapter_number}; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 0 | my $findings; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (my $chapter = $a{chapter}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $findings = $c->get("/report/$report/chapter/$chapter/finding?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } else { | ||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $findings = $c->get("/report/$report/finding?all=1") or die $c->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | return wantarray ? @$findings : $findings; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | sub get_form { | ||||||||||||||||||||||||||
|
Subroutine
get_form: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 243 | 0 | my $c = shift; | |||||||||||||||||||||||||||
| 244 | 0 | my $obj = shift; | |||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $uri = $obj->{uri} or die "no uri in ".Dumper($obj); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ($uri =~ m[/article]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 0 | $uri =~ s[article][article/form/update]; | |||||||||||||||||||||||||||
| 248 | } else { | ||||||||||||||||||||||||||||
| 249 | # The last backslash becomes /form/update | ||||||||||||||||||||||||||||
| 250 | 0 | $uri =~ s[/([^/]+)$][/form/update/$1]; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 0 | return $c->get($uri); | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 256 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 257 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my $url = $args{url} or die "missing url"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 0 | my $c = $class->new; | |||||||||||||||||||||||||||
| 261 | 0 | $c->url($url); | |||||||||||||||||||||||||||
| 262 | 0 | ▶ | $c->find_credentials->login or die "Failed to log in to $url"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | return $c; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 3 | 1; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | __END__ | ||||||||||||||||||||||||||||