| 1 | package Net::Checkpoint::Management::v1::Role::ObjectMethods; | ||||||||||||||||||||||||||||
| 2 | 3 | $Net::Checkpoint::Management::v1::Role::ObjectMethods::VERSION = '0.004003'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Role for Checkpoint Management API version 1.x method generation | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.024; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use MooX::Role::Parameterized; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp::Clan qw(^Net::Checkpoint::Management::v1); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Moo::Role; # last for cleanup | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | no warnings "experimental::signatures"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | requires qw( _create _list _get _update _delete ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 32 | ▶ | role { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=42.7
| |||||||||||||||||||||||||||||
| 23 | 32 | my $params = shift; | |||||||||||||||||||||||||||
| 24 | 32 | my $mop = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 32 | ▶ | if (exists $params->{singular} && defined $params->{singular}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"singular"} and defined $params->{"singular"}
MC/DC0%0/2
exists $params->{"singular"} and defined $params->{"singular"}
exists $params->{"singular"}
defined $params->{"singular"}
Truth table33%1/3
A and B
A= exists $params->{"singular"}B= defined $params->{"singular"}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $mop->method('create_' . $params->{singular} => sub ($self, $object_data) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | return $self->_create(join('/', | ||||||||||||||||||||||||||||
| 29 | '/web_api', | ||||||||||||||||||||||||||||
| 30 | 'v' . $self->api_version, | ||||||||||||||||||||||||||||
| 31 | $params->{create} | ||||||||||||||||||||||||||||
| 32 | 0 | ), $object_data); | |||||||||||||||||||||||||||
| 33 | }) | ||||||||||||||||||||||||||||
| 34 | 32 | ▶ | if exists $params->{create} && defined $params->{create}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"create"} and defined $params->{"create"}
MC/DC50%1/2
exists $params->{"create"} and defined $params->{"create"}
exists $params->{"create"}
defined $params->{"create"}
Truth table66%2/3
A and B
A= exists $params->{"create"}B= defined $params->{"create"}
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $mop->method('get_' . $params->{singular} => sub ($self, $query_params = {}) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 37 | return $self->_get(join('/', | ||||||||||||||||||||||||||||
| 38 | '/web_api', | ||||||||||||||||||||||||||||
| 39 | 'v' . $self->api_version, | ||||||||||||||||||||||||||||
| 40 | $params->{get} | ||||||||||||||||||||||||||||
| 41 | 0 | ), $query_params); | |||||||||||||||||||||||||||
| 42 | }) | ||||||||||||||||||||||||||||
| 43 | 32 | ▶ | if exists $params->{get} && defined $params->{get}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"get"} and defined $params->{"get"}
MC/DC0%0/2
exists $params->{"get"} and defined $params->{"get"}
exists $params->{"get"}
defined $params->{"get"}
Truth table33%1/3
A and B
A= exists $params->{"get"}B= defined $params->{"get"}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $mop->method('update_' . $params->{singular} => sub ($self, $object, $object_data) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 46 | 0 | my $updated_data = { %$object, %$object_data }; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (exists $params->{id_keys} && ref $params->{id_keys} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $params->{"id_keys"} and ref $params->{"id_keys"} eq "ARRAY"
MC/DC0%0/2
exists $params->{"id_keys"} and ref $params->{"id_keys"} eq "ARRAY"
exists $params->{"id_keys"}
ref $params->{"id_keys"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $params->{"id_keys"}B= ref $params->{"id_keys"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 48 | # ensure that only a single key is passed to the update call | ||||||||||||||||||||||||||||
| 49 | # the order of keys is the priority | ||||||||||||||||||||||||||||
| 50 | 0 | my @id_keys = $params->{id_keys}->@*; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | while (my $key = shift @id_keys) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | last | ||||||||||||||||||||||||||||
| 53 | if exists $updated_data->{$key} | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | && defined $updated_data->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $updated_data->{$key} and defined $updated_data->{$key}
MC/DC0%0/2
exists $updated_data->{$key} and defined $updated_data->{$key}
exists $updated_data->{$key}
defined $updated_data->{$key}
Truth table0%0/3
A and B
A= exists $updated_data->{$key}B= defined $updated_data->{$key}
| |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | delete $updated_data->{$_} | ||||||||||||||||||||||||||||
| 57 | 0 | for @id_keys; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | return $self->_update(join('/', | ||||||||||||||||||||||||||||
| 61 | '/web_api', | ||||||||||||||||||||||||||||
| 62 | 'v' . $self->api_version, | ||||||||||||||||||||||||||||
| 63 | $params->{update} | ||||||||||||||||||||||||||||
| 64 | 0 | ), $updated_data); | |||||||||||||||||||||||||||
| 65 | }) | ||||||||||||||||||||||||||||
| 66 | 32 | ▶ | if exists $params->{update} && defined $params->{update}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"update"} and defined $params->{"update"}
MC/DC50%1/2
exists $params->{"update"} and defined $params->{"update"}
exists $params->{"update"}
defined $params->{"update"}
Truth table66%2/3
A and B
A= exists $params->{"update"}B= defined $params->{"update"}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $mop->method('delete_' . $params->{singular} => sub ($self, $object) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 69 | return $self->_delete(join('/', | ||||||||||||||||||||||||||||
| 70 | '/web_api', | ||||||||||||||||||||||||||||
| 71 | 'v' . $self->api_version, | ||||||||||||||||||||||||||||
| 72 | $params->{delete} | ||||||||||||||||||||||||||||
| 73 | 0 | ), $object); | |||||||||||||||||||||||||||
| 74 | }) | ||||||||||||||||||||||||||||
| 75 | 32 | ▶ | if exists $params->{delete} && defined $params->{delete}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $params->{"delete"} and defined $params->{"delete"}
MC/DC50%1/2
exists $params->{"delete"} and defined $params->{"delete"}
exists $params->{"delete"}
defined $params->{"delete"}
Truth table66%2/3
A and B
A= exists $params->{"delete"}B= defined $params->{"delete"}
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $mop->method('find_' . $params->{singular} => sub ($self, $search_params = {}, $query_params = {}) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 78 | 0 | my $listname = 'list_' . $params->{object}; | |||||||||||||||||||||||||||
| 79 | 0 | my $list_key = $params->{list_key}; | |||||||||||||||||||||||||||
| 80 | 0 | for my $object ($self->$listname({ 'details-level' => 'full', %$query_params })->{$list_key}->@*) { | |||||||||||||||||||||||||||
| 81 | 0 | my $identical = 0; | |||||||||||||||||||||||||||
| 82 | 0 | for my $key (keys $search_params->%*) { | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( ref $search_params->{$key} eq 'Regexp') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( exists $object->{$key} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $object->{$key} and $object->{$key} =~ /$search_params->{$key}/u
MC/DC0%0/2
exists $object->{$key} and $object->{$key} =~ /$search_params->{$key}/u
exists $object->{$key}
$object->{$key} =~ /$search_params->{$key}/u
Truth table0%0/3
A and B
A= exists $object->{$key}B= $object->{$key} =~ /$search_params->{$key}/u
| |||||||||||||||||||||||||||||
| 85 | && $object->{$key} =~ $search_params->{$key}) { | ||||||||||||||||||||||||||||
| 86 | 0 | $identical++; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( exists $object->{$key} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $object->{$key} and $object->{$key} eq $search_params->{$key}
MC/DC0%0/2
exists $object->{$key} and $object->{$key} eq $search_params->{$key}
exists $object->{$key}
$object->{$key} eq $search_params->{$key}
Truth table0%0/3
A and B
A= exists $object->{$key}B= $object->{$key} eq $search_params->{$key}
| |||||||||||||||||||||||||||||
| 91 | && $object->{$key} eq $search_params->{$key}) { | ||||||||||||||||||||||||||||
| 92 | 0 | $identical++; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($identical == scalar keys $search_params->%*) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | return $object; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 0 | croak "object not found"; | |||||||||||||||||||||||||||
| 101 | 32 | }); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 32 | ▶ | if (exists $params->{object} && defined $params->{object}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $params->{"object"} and defined $params->{"object"}
MC/DC0%0/2
exists $params->{"object"} and defined $params->{"object"}
exists $params->{"object"}
defined $params->{"object"}
Truth table33%1/3
A and B
A= exists $params->{"object"}B= defined $params->{"object"}
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $mop->method('list_' . $params->{object} => sub ($self, $query_params = {}) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 106 | return $self->_list(join('/', | ||||||||||||||||||||||||||||
| 107 | '/web_api', | ||||||||||||||||||||||||||||
| 108 | 'v' . $self->api_version, | ||||||||||||||||||||||||||||
| 109 | $params->{list} | ||||||||||||||||||||||||||||
| 110 | 0 | ), $params->{list_key}, $query_params); | |||||||||||||||||||||||||||
| 111 | 32 | }); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 3 | }; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | 1; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||