| 1 | package Perinci::AccessUtil; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | our $DATE = '2015-09-06'; # DATE | |||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | our $VERSION = '0.06'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | our @EXPORT_OK = qw(insert_riap_stuffs_to_res | |||||||||||||||||||||||||||||||||||||||||
| 15 | strip_riap_stuffs_from_res | ||||||||||||||||||||||||||||||||||||||||||
| 16 | decode_args_in_riap_req); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | sub insert_riap_stuffs_to_res { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert_riap_stuffs_to_res: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | my ($res, $def_ver, $nmeta, $encode) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | $res->[3]{'riap.v'} //= $def_ver // 1.1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%4/4
$res->[3]{"riap.v"} //= $def_ver // "1.1"
$def_ver // "1.1"
MC/DC100%1/1
$res->[3]{"riap.v"} //= $def_ver // "1.1"
$res->[3]{"riap.v"}
Truth table100%2/2
A
A= $res->[3]{"riap.v"}
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 11 | ▶ | if ($res->[3]{'riap.v'} >= 1.2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | # do we need to base64-encode? | ||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | last unless $encode // 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$encode // 1
MC/DC100%1/1
$encode // 1
$encode
Truth table100%2/2
A
A= $encode
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 8 | ▶ | last if $res->[3]{'riap.result_encoding'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | ▶ | if ($nmeta) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | last unless $nmeta->{result}{schema} && | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $nmeta->{result}{schema}[0] eq 'buf'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$nmeta->{"result"}{"schema"} and $nmeta->{"result"}{"schema"}[0] eq "buf"
MC/DC50%1/2
$nmeta->{"result"}{"schema"} and $nmeta->{"result"}{"schema"}[0] eq "buf"
$nmeta->{"result"}{"schema"}
$nmeta->{"result"}{"schema"}[0] eq "buf"
Truth table66%2/3
A and B
A= $nmeta->{"result"}{"schema"}B= $nmeta->{"result"}{"schema"}[0] eq "buf"
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | last unless defined($res->[2]) && !ref($res->[2]) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $res->[2] and not ref $res->[2] and $res->[2] =~ /[^\x20-\x7f]/
defined $res->[2] and not ref $res->[2]
MC/DC100%3/3
defined $res->[2] and not ref $res->[2] and $res->[2] =~ /[^\x20-\x7f]/
defined $res->[2]
not ref $res->[2]
$res->[2] =~ /[^\x20-\x7f]/
Truth table100%4/4
A and not(B) and C
A= defined $res->[2]B= not ref $res->[2]C= $res->[2] =~ /[^\x20-\x7f]/
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | $res->[2] =~ /[^\x20-\x7f]/; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | $res->[2] = encode_base64($res->[2], ""); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | $res->[3]{'riap.result_encoding'} = 'base64'; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | $res; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub strip_riap_stuffs_from_res { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_riap_stuffs_from_res: called CC=11 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | my $ver = $res->[3]{'riap.v'} // 1.1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->[3]{"riap.v"} // "1.1"
MC/DC0%0/1
$res->[3]{"riap.v"} // "1.1"
$res->[3]{"riap.v"}
Truth table50%1/2
A
A= $res->[3]{"riap.v"}
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ▶ | return [501, "Riap version returned by server ($ver) is not supported, ". | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ver == "1.1" or $ver == "1.2"
MC/DC100%2/2
$ver == "1.1" or $ver == "1.2"
$ver == "1.1"
$ver == "1.2"
Truth table100%3/3
A or B
A= $ver == "1.1"B= $ver == "1.2"
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | "only recognize v1.1 and v1.2"] | ||||||||||||||||||||||||||||||||||||||||||
| 46 | unless $ver == 1.1 || $ver == 1.2; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if ($ver >= 1.2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | # check and strip riap.* | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | for my $k (keys %{$res->[3]}) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | 6 | ▶ | next unless $k =~ /\Ariap\./; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | my $val = $res->[3]{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | if ($k eq 'riap.v') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ($k eq 'riap.result_encoding') { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | return [501, "Unknown result_encoding returned by server ". | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | "($val), only base64 is supported"] | ||||||||||||||||||||||||||||||||||||||||||
| 57 | unless $val eq 'base64'; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | $res->[2] = decode_base64($res->[2]//''); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->[2] // ""
MC/DC0%0/1
$res->[2] // ""
$res->[2]
Truth table50%1/2
A
A= $res->[2]
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | return [501, "Unknown Riap attribute in result metadata ". | |||||||||||||||||||||||||||||||||||||||||
| 61 | "returned by server ($k)"]; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | delete $res->[3]{$k}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | $res; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | sub decode_args_in_riap_req { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_args_in_riap_req: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | my $req = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | my $v = $req->{v} // 1.1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->{"v"} // "1.1"
MC/DC100%1/1
$req->{"v"} // "1.1"
$req->{"v"}
Truth table100%2/2
A
A= $req->{"v"}
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | if ($v >= 1.2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | if ($req->{args}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my $args = $req->{args}; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | for (keys %$args) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | next unless /\A(.+):base64\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | $args->{$1} = decode_base64($args->{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | delete $args->{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | $req; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 88 | # ABSTRACT: Utility module for Riap client/server | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||