| 1 | package ArangoDB2::Base; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 22 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use Scalar::Util qw(blessed weaken); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # new | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # Arango organizes data hierarchically: Databases > Collections > Documents | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # This constructor can build ArangoDB2::Database, Collection, Document, Edge, | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # etc. objects which all follow the same pattern | ||||||||||||||||||||||||||||||||||||||||||
| 19 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 53 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 53 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | # new instance | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 53 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 53 | bless($self, $class); | |||||||||||||||||||||||||||||||||||||||||
| 25 | # process args | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 53 | ▶ | while (my $arg = shift) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | # if arg is a ref it should be another | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # ArangoDB::* object | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 124 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | # prevent circular ref | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 99 | weaken $arg; | |||||||||||||||||||||||||||||||||||||||||
| 32 | # create reference to parent object | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 99 | $self->{$arg->_class} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # if arg is a string then it is the "name" | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # of this object | ||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 25 | $self->name($arg); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # if we have a name and can get then try it | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 53 | ▶ | $self->get if defined $self->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->name and $self->can("get")
MC/DC0%0/2
defined $self->name and $self->can("get")
defined $self->name
$self->can("get")
Truth table66%2/3
A and B
A= defined $self->nameB= $self->can("get")
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | and $self->can('get'); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 53 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # api_path | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # return /_db/<db name>/_api | ||||||||||||||||||||||||||||||||||||||||||
| 51 | sub api_path | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
api_path: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $db_name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | = $self->database | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ? $self->database->name | ||||||||||||||||||||||||||||||||||||||||||
| 58 | : $self->name; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return '/' . join('/', '_db', $db_name, '_api', @_); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # arango | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # ArangoDB2 instance | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 31 | ▶ | sub arango { $_[0]->{arango} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
arango: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # collection | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # parent ArangoDB2::Collection instance | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub collection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collection: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # if value is already an object then set it | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->{collection} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # otherwise treat as name and get collection object | ||||||||||||||||||||||||||||||||||||||||||
| 80 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->{collection} = $self->database->collection($value); | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $self->{collection}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # data | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # ref to hash containing document data | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub data { shift->_get_set('data', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # database | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # parent ArangoDB2::Database instance | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 12 | ▶ | sub database { $_[0]->{database} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
database: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | # graph | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # parent ArangoDB2::Graph instance | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | sub graph { $_[0]->{graph} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
graph: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # id | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||||||||||||||||
| 105 | # ArangoDB _id | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub id { $_[0]->{id} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # name | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # name/handle of object | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 78 | ▶ | sub name { shift->_get_set_name('name', @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # rev | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||||||||||||||||
| 115 | # ArangoDB _rev | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub rev { $_[0]->{rev} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rev: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # _build_args | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # process args for requests | ||||||||||||||||||||||||||||||||||||||||||
| 121 | sub _build_args | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_args: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my($self, $args, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | # require hash ref for args | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $args = {} unless defined $args | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $args and ref $args and ref $args eq "HASH"
defined $args and ref $args
MC/DC0%0/3
defined $args and ref $args and ref $args eq "HASH"
defined $args
ref $args
ref $args eq "HASH"
Truth table0%0/4
A and B and C
A= defined $argsB= ref $argsC= ref $args eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | and ref $args and ref $args eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # if an explicit list is not passed for this call | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # then use global list for class | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $params ||= $self->_params; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params ||= $self->_params
MC/DC0%0/2
$params ||= $self->_params
$params
$self->_params
Truth table0%0/3
A ||= B
A= $paramsB= $self->_params
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | # for each of the allowed parameters use the | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # setter to set the value if it is passed and | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # and the value to the request args if it is | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # defined | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | for my $param (@$params) { | |||||||||||||||||||||||||||||||||||||||||
| 135 | # if params is pased in args then it supersedes | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # any value set as a property of the object | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if (exists $args->{$param}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | # run arg through setter with validate only | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # flag which will return the validated arg | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $args->{$param} = $self->$param($args->{$param}, 1); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # otherwise if the param is set then add to args | ||||||||||||||||||||||||||||||||||||||||||
| 143 | elsif (defined $self->$param) { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $args->{$param} = $self->$param; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # _build_self | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # | ||||||||||||||||||||||||||||||||||||||||||
| 153 | # copy param values from passed data to self | ||||||||||||||||||||||||||||||||||||||||||
| 154 | sub _build_self | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_self: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my($self, $data, $params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 157 | # require data | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | croak "Invalid Args" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # if an explicit list is not passed for this call | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # then use global list for class | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $params ||= $self->_params; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params ||= $self->_params
MC/DC0%0/2
$params ||= $self->_params
$params
$self->_params
Truth table0%0/3
A ||= B
A= $paramsB= $self->_params
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | # copy params | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | for my $param (@$params) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | $self->{$param} = delete $data->{$param} | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if exists $data->{$param}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | # copy _id and _rev to id/rev | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $self->{id} = delete $data->{_id} | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if exists $data->{_id}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | $self->{rev} = delete $data->{_rev} | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if exists $data->{_rev}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | # if user is set then use it as name | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if (exists $data->{user}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $self->{name} = delete $data->{user}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # otherwise try _key | ||||||||||||||||||||||||||||||||||||||||||
| 178 | elsif (exists $data->{_key}) { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | $self->{name} = delete $data->{_key} | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 181 | # copy to and from | ||||||||||||||||||||||||||||||||||||||||||
| 182 | $self->{from} = delete $data->{_from} | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if exists $data->{_from}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | $self->{to} = delete $data->{_to} | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if exists $data->{_to}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # _get_set | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # either get or set value. | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # setting value returns self. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | sub _get_set | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 42 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_set: called CC=3 SCAR=16.0
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 42 | my($self, $param, $value, $validate) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 42 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | # if we are only validating then return valid value | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | return $value if $validate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | # set value and return self | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $self->{$param} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # return currently set value | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 42 | return $self->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | # _get_set_bool | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # either get value or set JSON bool value. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | # setting value returns self. | ||||||||||||||||||||||||||||||||||||||||||
| 215 | sub _get_set_bool | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_set_bool: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my($self, $param, $value, $validate) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | # accept "true" as JSON bool false | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($value eq "true") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $value = JSON::XS::true; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # accept "false" as JSON bool false | ||||||||||||||||||||||||||||||||||||||||||
| 225 | elsif ($value eq "false") { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $value = JSON::XS::false; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # use the true/false of value to determine JSON bool | ||||||||||||||||||||||||||||||||||||||||||
| 229 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | $value = $value ? JSON::XS::true : JSON::XS::false; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # if we are only validating then return valid value | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | return $value if $validate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | # set value and return self | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | $self->{$param} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # return currently set value | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return $self->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # _get_set_id | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # get/set id with either string or object | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # setting a value returns self | ||||||||||||||||||||||||||||||||||||||||||
| 248 | sub _get_set_id | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_set_id: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my($self, $param, $value, $validate) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | # get value from an ArangoDB2 object | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ( blessed $value && $value->can('id') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($value) and $value->can("id")
MC/DC0%0/2
builtin::blessed($value) and $value->can("id")
builtin::blessed($value)
$value->can("id")
Truth table0%0/3
A and B
A= builtin::blessed($value)B= $value->can("id")
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $value = $value->id | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | # if we are only validating then return valid value | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | return $value if $validate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | # set value and return self | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->{$param} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | # return currently set value | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return $self->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | # _get_set_name | ||||||||||||||||||||||||||||||||||||||||||
| 270 | # | ||||||||||||||||||||||||||||||||||||||||||
| 271 | # get/set name with either name or object | ||||||||||||||||||||||||||||||||||||||||||
| 272 | # setting a value returns self | ||||||||||||||||||||||||||||||||||||||||||
| 273 | sub _get_set_name | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 78 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_set_name: called CC=5 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 78 | my($self, $param, $value, $validate) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 78 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | # get value from an ArangoDB2 object | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 25 | ▶ | if ( blessed $value && $value->can('name') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($value) and $value->can("name")
MC/DC0%0/2
builtin::blessed($value) and $value->can("name")
builtin::blessed($value)
$value->can("name")
Truth table33%1/3
A and B
A= builtin::blessed($value)B= $value->can("name")
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $value = $value->name | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # if we are only validating then return valid value | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 25 | ▶ | return $value if $validate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | # set value and return self | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 25 | $self->{$param} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 25 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | # return currently set value | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 53 | return $self->{$param}; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 22 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | __END__ | ||||||||||||||||||||||||||||||||||||||||||