| 1 | package Net::Journyx::Object::WithAttrs; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | #requires 'jx'; Moose doesn't like that jx is only accessor | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | has object_type_for_attributes => ( | ||||||||||||||||||||||||||||
| 7 | is => 'ro', | ||||||||||||||||||||||||||||
| 8 | isa => 'Str', | ||||||||||||||||||||||||||||
| 9 | lazy => 1, | ||||||||||||||||||||||||||||
| 10 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 11 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | require Net::Journyx::Attribute; | |||||||||||||||||||||||||||
| 14 | 0 | my $valid_types = Net::Journyx::Attribute | |||||||||||||||||||||||||||
| 15 | ->new(jx => $self->jx) | ||||||||||||||||||||||||||||
| 16 | ->valid_object_types; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | my $guessed_type = lc((split /::/, ref($self))[-1]).'s'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return $guessed_type if grep $guessed_type eq $_, @$valid_types; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | die "Can not guess object type of ". ref($self) ." required for attributes." | |||||||||||||||||||||||||||
| 23 | ." It's possible that this class can not have attributes at all"; | ||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | 5 | ); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | use Net::Journyx::Attribute; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub attribute { | ||||||||||||||||||||||||||
|
Subroutine
attribute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 31 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | return $self->get_attribute( $name ) unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 0 | return $self->set_attribute( $name, @_ ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub load_attribute { | ||||||||||||||||||||||||||
|
Subroutine
load_attribute: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | return Net::Journyx::Attribute->new(jx => $self->jx)->load( | |||||||||||||||||||||||||||
| 41 | object => $self, | ||||||||||||||||||||||||||||
| 42 | name => $name, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub get_attribute { | ||||||||||||||||||||||||||
|
Subroutine
get_attribute: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $attr = $self->load_attribute($name); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $operation = 'getAttribute'; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | die "Unable to read ". $self->jx_record_class ." attribute '$name' in Journyx. This may indicate a misconfiguration of your Journyx database." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | unless $attr->id; | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | my $data_type = $attr->data_type; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $data_type eq 'NUMBER' || $data_type eq 'INTEGER') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$data_type eq "NUMBER" or $data_type eq "INTEGER"
MC/DC0%0/2
$data_type eq "NUMBER" or $data_type eq "INTEGER"
$data_type eq "NUMBER"
$data_type eq "INTEGER"
Truth table0%0/3
A or B
A= $data_type eq "NUMBER"B= $data_type eq "INTEGER"
| |||||||||||||||||||||||||||||
| 58 | 0 | $operation .= ucfirst lc $data_type; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $response = $self->jx->soap->basic_call( | |||||||||||||||||||||||||||
| 62 | $operation, | ||||||||||||||||||||||||||||
| 63 | object_type => $self->object_type_for_attributes, | ||||||||||||||||||||||||||||
| 64 | object_id => $self->id, | ||||||||||||||||||||||||||||
| 65 | id_attr_type => $attr->id, | ||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( ref($response) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | # special case: empty value | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | unless ( exists $response->{'Result'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | warn "expected that hash will have 'Result', but got: " | ||||||||||||||||||||||||||||
| 71 | 0 | . Dumper( $response->{'Result'} ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return undef unless defined $response->{'Result'} && length $response->{'Result'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $response->{"Result"} and length $response->{"Result"}
MC/DC0%0/2
defined $response->{"Result"} and length $response->{"Result"}
defined $response->{"Result"}
length $response->{"Result"}
Truth table0%0/3
A and B
A= defined $response->{"Result"}B= length $response->{"Result"}
| |||||||||||||||||||||||||||||
| 74 | 0 | return $response->{'Result'}; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | return $response; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub set_attributes { | ||||||||||||||||||||||||||
|
Subroutine
set_attributes: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my %template = ( | |||||||||||||||||||||||||||
| 83 | object_type => $self->object_type_for_attributes, | ||||||||||||||||||||||||||||
| 84 | object_id => $self->id, | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my @calls = (); | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | while ( my ($name, $value) = splice @_, 0, 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | my $attr = blessed($name)? $name : $self->load_attribute($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | die "Unable to set/remove ". $self->jx_record_class ." attribute '$name' in Journyx." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | ." This may indicate a misconfiguration of your Journyx database." | ||||||||||||||||||||||||||||
| 93 | unless $attr->id; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | unless ( defined $value ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | push @calls, 'deleteAttribute', { %template, id_attr_type => $attr->id }; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | else { | ||||||||||||||||||||||||||||
| 99 | # batch API has setAttribute for any type, no need in suffix | ||||||||||||||||||||||||||||
| 100 | 0 | push @calls, 'setAttribute', { | |||||||||||||||||||||||||||
| 101 | %template, | ||||||||||||||||||||||||||||
| 102 | id_attr_type => $attr->id, | ||||||||||||||||||||||||||||
| 103 | value => $value, | ||||||||||||||||||||||||||||
| 104 | overwrite_existing => 1, | ||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | return $self->jx->soap->batch_call( @calls ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub set_attribute { | ||||||||||||||||||||||||||
|
Subroutine
set_attribute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 115 | 0 | my $value = shift; | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | return $self->del_attribute( $name, @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | unless defined $value; | ||||||||||||||||||||||||||||
| 118 | 0 | my %rest = ( | |||||||||||||||||||||||||||
| 119 | overwrite_existing => 1, | ||||||||||||||||||||||||||||
| 120 | @_ | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | my $attr = blessed($name)? $name : $self->load_attribute($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | my $operation = 'setAttribute'; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | die "Unable to update ". $self->jx_record_class ." attribute '$name' in Journyx. This may indicate a misconfiguration of your Journyx database." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | unless $attr->id; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | my $data_type = $attr->data_type; | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ( $data_type eq 'NUMBER' || $data_type eq 'INTEGER') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$data_type eq "NUMBER" or $data_type eq "INTEGER"
MC/DC0%0/2
$data_type eq "NUMBER" or $data_type eq "INTEGER"
$data_type eq "NUMBER"
$data_type eq "INTEGER"
Truth table0%0/3
A or B
A= $data_type eq "NUMBER"B= $data_type eq "INTEGER"
| |||||||||||||||||||||||||||||
| 132 | 0 | $operation .= ucfirst lc $data_type; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return $self->jx->soap->basic_call( | |||||||||||||||||||||||||||
| 136 | $operation, | ||||||||||||||||||||||||||||
| 137 | %rest, | ||||||||||||||||||||||||||||
| 138 | object_type => $self->object_type_for_attributes, | ||||||||||||||||||||||||||||
| 139 | object_id => $self->id, | ||||||||||||||||||||||||||||
| 140 | id_attr_type => $attr->id, | ||||||||||||||||||||||||||||
| 141 | value => $value, | ||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub del_attribute { | ||||||||||||||||||||||||||
|
Subroutine
del_attribute: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 146 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 147 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $attr = blessed($name)? $name : $self->load_attribute($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $operation = 'deleteAttribute'; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | die "Unable to remove ". $self->jx_record_class ." attribute '$name' in Journyx. This may indicate a misconfiguration of your Journyx database." | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | unless $attr->id; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | return $self->jx->soap->basic_call( | |||||||||||||||||||||||||||
| 157 | $operation, | ||||||||||||||||||||||||||||
| 158 | object_type => $self->object_type_for_attributes, | ||||||||||||||||||||||||||||
| 159 | object_id => $self->id, | ||||||||||||||||||||||||||||
| 160 | id_attr_type => $attr->id, | ||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 5 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | 5 | 1; | |||||||||||||||||||||||||||