| 1 | package Perinci::Access::Lite; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Perinci::AccessUtil qw(strip_riap_stuffs_from_res); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our $DATE = '2022-10-28'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $DIST = 'Perinci-Access-Lite'; # DIST | |||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | our $VERSION = '0.150'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | $args{riap_version} //= 1.1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"riap_version"} //= "1.1"
MC/DC0%0/1
$args{"riap_version"} //= "1.1"
$args{"riap_version"}
Truth table50%1/2
A
A= $args{"riap_version"}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | bless \%args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | # copy-pasted from SHARYANTO::Package::Util | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | sub __package_exists { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__package_exists: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | my $pkg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | return unless $pkg =~ /\A\w+(::\w+)*\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | if ($pkg =~ s/::(\w+)\z//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | return !!${$pkg . "::"}{$1 . "::"}; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | return !!$::{$pkg . "::"}; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | ▶ | sub request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=49 SCAR=55.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | my ($self, $action, $url, $extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | #say "D:request($action => $url)"; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | $extra //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$extra //= {}
MC/DC0%0/1
$extra //= {}
$extra
Truth table50%1/2
A
A= $extra
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | my $v = $extra->{v} // 1.1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$extra->{"v"} // "1.1"
MC/DC0%0/1
$extra->{"v"} // "1.1"
$extra->{"v"}
Truth table50%1/2
A
A= $extra->{"v"}
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | ▶ | if ($v ne '1.1' && $v ne '1.2') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$v ne "1.1" and $v ne "1.2"
MC/DC0%0/2
$v ne "1.1" and $v ne "1.2"
$v ne "1.1"
$v ne "1.2"
Truth table33%1/3
A and B
A= $v ne "1.1"B= $v ne "1.2"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return [501, "Riap protocol not supported, must be 1.1 or 1.2"]; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | my $res; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | ▶ | if ($url =~ m!\A(?:pl:)?/(\w+(?:/\w+)*)/(\w*)\z!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | my ($mod_uripath, $func) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | (my $pkg = $mod_uripath) =~ s!/!::!g; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | my $mod_pm = "$mod_uripath.pm"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | my $pkg_exists; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | LOAD: | ||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | last if exists $INC{$mod_pm}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | $pkg_exists = __package_exists($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 60 | # special names | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | ▶ | last LOAD if $pkg =~ /\A(main)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | last if $pkg_exists && defined(${"$pkg\::VERSION"}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pkg_exists and defined ${"${pkg}::VERSION";}
MC/DC0%0/2
$pkg_exists and defined ${"${pkg}::VERSION";}
$pkg_exists
defined ${"${pkg}::VERSION";}
Truth table33%1/3
A and B
A= $pkg_existsB= defined ${"${pkg}::VERSION";}
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | #say "D:Loading $pkg ..."; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | eval { require $mod_pm }; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | return [500, "Can't load module $pkg: $@"] if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | if ($action eq 'list') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | return [501, "Action 'list' not implemented for ". | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | "non-package entities"] | ||||||||||||||||||||||||||||||||||||||||||
| 71 | if length($func); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $spec = \%{"$pkg\::SPEC"}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return [200, "OK (list)", [grep {/\A\w+\z/} sort keys %$spec]]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } elsif ($action eq 'info') { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $data = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | uri => "$mod_uripath/$func", | ||||||||||||||||||||||||||||||||||||||||||
| 78 | type => (!length($func) ? "package" : | ||||||||||||||||||||||||||||||||||||||||||
| 79 | $func =~ /\A\w+\z/ ? "function" : | ||||||||||||||||||||||||||||||||||||||||||
| 80 | $func =~ /\A[\@\$\%]/ ? "variable" : | ||||||||||||||||||||||||||||||||||||||||||
| 81 | "?"), | ||||||||||||||||||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return [200, "OK (info)", $data]; | |||||||||||||||||||||||||||||||||||||||||
| 84 | ▶ | } elsif ($action eq 'meta' || $action eq 'call') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$action eq "meta" or $action eq "call"
MC/DC0%0/2
$action eq "meta" or $action eq "call"
$action eq "meta"
$action eq "call"
Truth table66%2/3
A or B
A= $action eq "meta"B= $action eq "call"
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | ▶ | return [501, "Action 'call' not implemented for package entity"] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not length $func and $action eq "call"
MC/DC100%2/2
not length $func and $action eq "call"
not length $func
$action eq "call"
Truth table100%3/3
not(A) and B
A= not length $funcB= $action eq "call"
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | if !length($func) && $action eq 'call'; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my $meta; | |||||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | if (length $func) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | $meta = ${"$pkg\::SPEC"}{$func} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | or return [ | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 500, "No metadata for '$url' (". | ||||||||||||||||||||||||||||||||||||||||||
| 94 | ($pkg_exists ? "package '$pkg' exists, perhaps you mentioned '$pkg' somewhere without actually loading the module, or perhaps '$func' is a typo?" : | ||||||||||||||||||||||||||||||||||||||||||
| 95 | "package '$pkg' doesn't exist, perhaps '$mod_uripath' or '$func' is a typo?") . | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ")"]; | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $meta = ${"$pkg\::SPEC"}{':package'} // {v=>1.1}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
do {
"${pkg}::SPEC"
}->{":package"} // {"v", "1.1"}
MC/DC0%0/1
do {
"${pkg}::SPEC"
}->{":package"} // {"v", "1.1"}
do {
"${pkg}::SPEC"
}->{":package"}
Truth table50%1/2
A
A= do {
"${pkg}::SPEC"
}->{":package"}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | ▶ | $meta->{entity_v} //= ${"$pkg\::VERSION"}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$meta->{"entity_v"} //= ${"${pkg}::VERSION";}
MC/DC0%0/2
$meta->{"entity_v"} //= ${"${pkg}::VERSION";}
$meta->{"entity_v"}
${"${pkg}::VERSION";}
Truth table66%2/3
A //= B
A= $meta->{"entity_v"}B= ${"${pkg}::VERSION";}
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | $meta->{entity_date} //= ${"$pkg\::DATE"}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$meta->{"entity_date"} //= ${"${pkg}::DATE";}
MC/DC0%0/2
$meta->{"entity_date"} //= ${"${pkg}::DATE";}
$meta->{"entity_date"}
${"${pkg}::DATE";}
Truth table66%2/3
A //= B
A= $meta->{"entity_date"}B= ${"${pkg}::DATE";}
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | require Perinci::Sub::Normalize; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | $meta = Perinci::Sub::Normalize::normalize_function_metadata($meta); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | if ($action eq 'meta') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | $meta->{_orig_args_as} = $meta->{args_as}; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | $meta->{args_as} = 'hash'; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | $meta->{_orig_result_naked} = $meta->{result_naked}; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | $meta->{result_naked} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | return [200, "OK ($action)", $meta]; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | # form args (and add special args) | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | my $args = { %{$extra->{args} // {}} }; # shallow copy | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$extra->{"args"} // {}
MC/DC0%0/1
$extra->{"args"} // {}
$extra->{"args"}
Truth table50%1/2
A
A= $extra->{"args"}
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | if ($meta->{features} && $meta->{features}{progress}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$meta->{"features"} and $meta->{"features"}{"progress"}
MC/DC0%0/2
$meta->{"features"} and $meta->{"features"}{"progress"}
$meta->{"features"}
$meta->{"features"}{"progress"}
Truth table33%1/3
A and B
A= $meta->{"features"}B= $meta->{"features"}{"progress"}
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | require Progress::Any; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $args->{-progress} = Progress::Any->get_indicator; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # convert args | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | ▶ | my $aa = $meta->{args_as} // 'hash'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$meta->{"args_as"} // "hash"
MC/DC0%0/1
$meta->{"args_as"} // "hash"
$meta->{"args_as"}
Truth table50%1/2
A
A= $meta->{"args_as"}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | my @args; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | if ($aa =~ /array/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | require Perinci::Sub::ConvertArgs::Array; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $convres = Perinci::Sub::ConvertArgs::Array::convert_args_to_array( | |||||||||||||||||||||||||||||||||||||||||
| 127 | args => $args, meta => $meta, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return $convres unless $convres->[0] == 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($aa =~ /ref/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | @args = ($convres->[2]); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | @args = @{ $convres->[2] }; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } elsif ($aa eq 'hashref') { | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | @args = ({ %$args }); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # hash | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | @args = %$args; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | # call! | ||||||||||||||||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $res = &{"$pkg\::$func"}(@args); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # add envelope | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | if ($meta->{result_naked}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $res = [200, "OK (envelope added by ".__PACKAGE__.")", $res]; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # add hint that result is binary | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if (defined $res->[2]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | ▶ | if ($meta->{result} && $meta->{result}{schema} && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$meta->{"result"} and $meta->{"result"}{"schema"} and $meta->{"result"}{"schema"}[0] eq "buf"
$meta->{"result"} and $meta->{"result"}{"schema"}
MC/DC0%0/3
$meta->{"result"} and $meta->{"result"}{"schema"} and $meta->{"result"}{"schema"}[0] eq "buf"
$meta->{"result"}
$meta->{"result"}{"schema"}
$meta->{"result"}{"schema"}[0] eq "buf"
Truth table25%1/4
A and B and C
A= $meta->{"result"}B= $meta->{"result"}{"schema"}C= $meta->{"result"}{"schema"}[0] eq "buf"
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | $meta->{result}{schema}[0] eq 'buf') { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $res->[3]{'x.hint.result_binary'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return [501, "Unknown/unsupported action '$action'"]; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | } elsif ($url =~ m!\Ahttps?:/(/?)!i) { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $is_unix = !$1; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $ht; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | require JSON; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | state $json = JSON->new->allow_nonref; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($is_unix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | require HTTP::Tiny::UNIX; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $ht = HTTP::Tiny::UNIX->new; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | require HTTP::Tiny; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $ht = HTTP::Tiny->new; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | my %headers = ( | ||||||||||||||||||||||||||||||||||||||||||
| 177 | "x-riap-v" => $self->{riap_version}, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | "x-riap-action" => $action, | |||||||||||||||||||||||||||||||||||||||||
| 179 | "x-riap-fmt" => "json", | ||||||||||||||||||||||||||||||||||||||||||
| 180 | "content-type" => "application/json", | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $args = $extra->{args} // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$extra->{"args"} // {}
MC/DC0%0/1
$extra->{"args"} // {}
$extra->{"args"}
Truth table0%0/2
A
A= $extra->{"args"}
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | for (keys %$extra) { | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | next if /\Aargs\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $headers{"x-riap-$_"} = $extra->{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $htres = $ht->post( | |||||||||||||||||||||||||||||||||||||||||
| 188 | $url, { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | headers => \%headers, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | content => $json->encode($args), | ||||||||||||||||||||||||||||||||||||||||||
| 191 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 192 | return [500, "Network error: $htres->{status} - $htres->{reason}"] | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if $htres->{status} != 200; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | return [500, "Server error: didn't return JSON (".$htres->{headers}{'content-type'}.")"] | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | unless $htres->{headers}{'content-type'} eq 'application/json'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | return [500, "Server error: didn't return Riap 1.1 response (".$htres->{headers}{'x-riap-v'}.")"] | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | unless $htres->{headers}{'x-riap-v'} =~ /\A1\.1(\.\d+)?\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $res = $json->decode($htres->{content}); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return [501, "Unsupported scheme or bad URL '$url'"]; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | strip_riap_stuffs_from_res($res); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 207 | # ABSTRACT: A lightweight Riap client library | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | __END__ | ||||||||||||||||||||||||||||||||||||||||||