| 1 | package Google::RestApi::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '2.2.5'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use feature 'state'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use File::Spec::Functions qw( catfile ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Basename qw( dirname ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Hash::Merge (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Log::Log4perl qw( :easy ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Type::Params qw( signature ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Types::Standard qw( Str StrMatch Int CodeRef HashRef HasMethods Any slurpy ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use YAML::Any qw( Dump LoadFile ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Google::RestApi::Types qw( ReadableFile ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | no autovivification; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | named_extra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | merge_config_file resolve_config_file_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | flatten_range | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | dims_any dims_all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | cl_black cl_white | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | strip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | paginate_api | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | paginated_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # used by validation with type::params. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # similar to allow_extra in params::validate, simply returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # extra key/value pairs we aren't interested in in the checked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # argument hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1320 | ▶ | sub named_extra { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
named_extra: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # v2 signature returns blessed hashref; dereference if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1320 | ▶ | my @args = @_ == 1 && ref $_[0] ? %{$_[0]} : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and ref $_[0]
MC/DC50%1/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1320 | state $check = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | _extra_ => HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | validated => slurpy HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1320 | my $p = $check->(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1319 | my $extra = delete $p->{_extra_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1319 | my %p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1319 | ▶ | %p = %{ $p->{validated} } if $p->{validated}; # these are validated by the caller. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1319 | @p{ keys %$extra } = values %$extra; # stuff back the ones the caller wasn't interested in. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1319 | return \%p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 397 | ▶ | sub merge_config_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_config_file: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 397 | state $check = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | config_file => ReadableFile, { optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | _extra_ => slurpy HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 397 | my $passed_config = named_extra($check->(@_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 395 | my $config_file = $passed_config->{config_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 395 | ▶ | return $passed_config if !$config_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 248 | my $config_from_file = eval { LoadFile($config_file); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 248 | ▶ | LOGDIE "Unable to load config file '$config_file': $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Support an optional 'google_restapi' top-level key so the config file can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # be shared with other apps. Use that section if present, else use the root. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 248 | ▶ | $config_from_file = $config_from_file->{google_restapi} // $config_from_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$$config_from_file{"google_restapi"} // $config_from_file
MC/DC0%0/2
$$config_from_file{"google_restapi"} // $config_from_file
$$config_from_file{"google_restapi"}
$config_from_file
Truth table66%2/3
A // B
A= $$config_from_file{"google_restapi"}B= $config_from_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # left_precedence, the passed config wins over anything in the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # can't merge coderefs, error comes from Storable buried deep in hash::merge. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 248 | my $merged_config = Hash::Merge::merge($passed_config, $config_from_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 248 | TRACE("Config used:\n". Dump($merged_config)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 248 | return $merged_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # a standard way to store file names in a config and resolve them | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # to a full path. can be used in Auth configs, possibly others. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # see sub RestApi::auth for more. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 541 | ▶ | sub resolve_config_file_path { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve_config_file_path: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 541 | state $check = signature(positional => [HashRef, Str]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 541 | my ($config, $file_key) = $check->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 541 | ▶ | my $config_file = $config->{$file_key} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 149 | ▶ | return $config_file if -f $config_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 140 | my $full_file_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 140 | ▶ | if ($file_key ne 'config_file' && $config->{config_file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$file_key ne "config_file" and $$config{"config_file"}
MC/DC50%1/2
$file_key ne "config_file" and $$config{"config_file"}
$file_key ne "config_file"
$$config{"config_file"}
Truth table66%2/3
A and B
A= $file_key ne "config_file"B= $$config{"config_file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | my $dir = dirname($config->{config_file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | my $path = catfile($dir, $config_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | ▶ | $full_file_path = $path if -f $path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 140 | ▶ | if (!$full_file_path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 139 | my $dir = $config->{config_dir}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 139 | ▶ | if ($dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 136 | my $path = catfile($dir, $config_file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 136 | ▶ | $full_file_path = $path if -f $path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 140 | ▶ | LOGDIE("Unable to resolve config file '$file_key => $config_file' to a full file path") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | if !$full_file_path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # action at a distance, but is convenient to stuff the real file name in the config here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 137 | $config->{$file_key} = $full_file_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 137 | return $full_file_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # these are just used for debug message just above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # to display the original range in a pretty format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 900 | ▶ | sub flatten_range { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flatten_range: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 900 | my $range = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 900 | ▶ | $range = $range->range_to_hash() if blessed($range); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 900 | ▶ | return 'False' if !$range; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 857 | ▶ | return $range if !ref($range); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 251 | ▶ | return _flatten_range_hash($range) if ref($range) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 101 | ▶ | return _flatten_range_array($range) if ref($range) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | LOGDIE("Unable to flatten: " . ref($range)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 150 | ▶ | sub _flatten_range_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flatten_range_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 150 | my $range = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 150 | my @flat = map { "$_ => " . flatten_range($range->{$_}); } sort keys %$range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 150 | my $flat = join(', ', @flat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 150 | return "{ $flat }"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 101 | ▶ | sub _flatten_range_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flatten_range_array: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 101 | my $range = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 101 | my @flat = map { flatten_range($_); } @$range; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 101 | my $flat = join(', ', @flat); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 101 | return "[ $flat ]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # changes perl boolean to json boolean. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 38 | ▶ | sub bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bool: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 38 | my $bool = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 38 | ▶ | return 'true' if !defined $bool; # bold() should turn on bold. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 25 | ▶ | return 'false' if $bool =~ qr/^false$/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 23 | ▶ | return $bool ? 'true' : 'false'; # converts bold(0) to 'false'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 269 | ▶ | sub dims_any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dims_any: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 269 | state $check = signature(positional => [StrMatch[qr/^(col|row)/i]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 269 | my ($dims) = $check->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 268 | ▶ | return $dims =~ /^col/i ? "COLUMNS" : "ROWS"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | sub dims_all { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dims_all: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | my $dims = eval { dims_any(@_); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | ▶ | return $dims if $dims; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | state $check = signature(positional => [StrMatch[qr/^all/i]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ($dims) = $check->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | return "ALL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 5 | ▶ | sub cl_black { { red => 0, blue => 0, green => 0, alpha => 1 }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cl_black: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 5 | ▶ | sub cl_white { { red => 1, blue => 1, green => 1, alpha => 1 }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cl_white: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub strip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $p = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $p =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 52 | ▶ | sub paginate_api { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paginate_api: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 52 | state $check = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | api_call => CodeRef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | result_key => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | max_pages => Int, { default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | page_callback => CodeRef, { optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 52 | my $p = $check->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 52 | my @list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | my $next_page_token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 52 | my $page = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 52 | my $keep_going = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 53 | my $result = $p->{api_call}->($next_page_token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 53 | my $items = $result->{ $p->{result_key} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 53 | ▶ | push(@list, $items->@*) if $items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 53 | $next_page_token = $result->{nextPageToken}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 53 | $page++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 53 | ▶ | if ($p->{page_callback} && $items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$p{"page_callback"} and $items
MC/DC50%1/2
$$p{"page_callback"} and $items
$$p{"page_callback"}
$items
Truth table66%2/3
A and B
A= $$p{"page_callback"}B= $items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | $keep_going = $p->{page_callback}->($result); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 52 | ▶ | } until !$keep_going || !$next_page_token || ($p->{max_pages} > 0 && $page >= $p->{max_pages}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not $keep_going && $next_page_token or $$p{"max_pages"} > 0 and $page >= $$p{"max_pages"}
$keep_going && $next_page_token
$$p{"max_pages"} > 0 and $page >= $$p{"max_pages"}
MC/DC50%2/4
not $keep_going && $next_page_token or $$p{"max_pages"} > 0 and $page >= $$p{"max_pages"}
$keep_going
$next_page_token
$$p{"max_pages"} > 0
$page >= $$p{"max_pages"}
Truth table60%3/5
not(A && B) or C and D
A= $keep_goingB= $next_page_tokenC= $$p{"max_pages"} > 0D= $page >= $$p{"max_pages"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 52 | return @list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 52 | ▶ | sub paginated_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
paginated_list: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 52 | state $check = signature( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | bless => !!0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | named => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | api => HasMethods['api'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | uri => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | result_key => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | default_fields => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | fields_prefix => Str, { default => 'nextPageToken' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | max_pages => Int, { default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | page_callback => CodeRef, { optional => 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | params => HashRef, { default => {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 52 | my $p = $check->(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 52 | my $params = $p->{params}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 52 | ▶ | $params->{fields} //= $p->{default_fields}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$params{"fields"} //= $$p{"default_fields"}
MC/DC0%0/2
$$params{"fields"} //= $$p{"default_fields"}
$$params{"fields"}
$$p{"default_fields"}
Truth table33%1/3
A //= B
A= $$params{"fields"}B= $$p{"default_fields"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 52 | $params->{fields} = "$p->{fields_prefix}, $params->{fields}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 52 | my $api = $p->{api}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 52 | my $uri = $p->{uri}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | return paginate_api( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 53 | ▶ | api_call => sub { $params->{pageToken} = $_[0] if $_[0]; $api->api(uri => $uri, params => $params); }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | result_key => $p->{result_key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | max_pages => $p->{max_pages}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 52 | ▶ | ($p->{page_callback} ? (page_callback => $p->{page_callback}) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||