Journyx/Attribute.pm

filter: Statementstmt 20.4% 17 / 83 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 18.7% 3 / 16 Podpod 0.0% 0 / 7 totaltotal 11.6% 20 / 172 CC 24 SCAR 35.0
CC
24
Cov
13%
load
90.0
set_default_value
42.0
create
20.0
CRAP 33.3
« Journyx/Object/WithAttrs.pm ↑ Summary Journyx/SOAP.pm »
1 package Net::Journyx::Attribute;
2 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 extends 'Net::Journyx::Object';
5 5 with 'Net::Journyx::Object::Loadable' => {
6 check_on => [qw(delete)],
7 drop_on => [qw(create delete)],
8 };
9  
10 5 ▶use constant jx_record_class => 'AttributeTypeRecord';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use constant jx_strip_record_suffix => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 my @jx_columns = ();
14 has jx_columns => (
15 is => 'ro',
16 init_arg => undef,
17 isa => 'ArrayRef[Str]',
18 lazy => 1,
19 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
20 0 ▶ return [@jx_columns] if @jx_columns;
Branch: 1 branch
BranchTrueFalseTotal
if @jx_columns 0 0 0
21 0 my %columns = $_[0]->jx->soap->record_columns( $_[0]->jx_record_class );
22 0 @jx_columns = keys %columns;
23 0 return [@jx_columns];
24 },
25 5 );
26  
27 has jx_record => (
28 is => 'rw',
29 isa => 'HashRef',
30 init_arg => undef,
31 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 5 );
33  
34 5 my @valid_object_types = ();
35 has valid_object_types => (
36 is => 'ro',
37 isa => 'ArrayRef[Str]',
38 init_arg => 0,
39 lazy => 1,
40 0 ▶ default => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
41 0 ▶ return [@valid_object_types] if @valid_object_types;
Branch: 1 branch
BranchTrueFalseTotal
if @valid_object_types 0 0 0
42 0 my $res = (shift)->jx->soap->basic_call('getAttributeObjectTypes');
43 0 ▶ @valid_object_types = sort ref($res) eq 'ARRAY'? @$res : $res;
Branch: 1 branch
BranchTrueFalseTotal
ref $res eq 'ARRAY' ? : 0 0 0
44 0 return [@valid_object_types];
45 },
46 5 );
47  
48 0 ▶sub is_valid_type {
Subroutine is_valid_type: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my $self = shift;
50 0 my $type = shift;
51  
52 0 local $@;
53 0 my $response = eval { $self->jx->soap->basic_call(
54 'checkAttributeDataType', data_type => $type
55 ) };
56 0 return $response;
57 }
58  
59 0 ▶sub id { return $_[0]->jx_record->{'id_attr_type'} }
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
60 0 ▶sub data_type { return $_[0]->jx_record->{'attr_type'} }
Subroutine data_type: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 0 ▶sub load {
Subroutine load: not called CC=9 SCAR=45.0
63 0 my $self = shift;
64 0 my %args = (
65 object => undef,
66 name => undef,
67 @_,
68 );
69 0 ▶ unless ( blessed($args{'object'})
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")) 0 0 0
Condition0%0/6
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")
!ll&&!rl&&r
000
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")
builtin::blessed($args{"object"}) $args{"object"}->isa("Moose::Object") $args{"object"}->does("Net::Journyx::Object::WithAttrs")
Truth table0%0/4
A and B and C
A= builtin::blessed($args{"object"})B= $args{"object"}->isa("Moose::Object")C= $args{"object"}->does("Net::Journyx::Object::WithAttrs")
ABCresult
0XX0
10X0
1100
1111
70 && $args{'object'}->isa('Moose::Object')
71 && $args{'object'}->does('Net::Journyx::Object::WithAttrs')
72 ) {
73 0 die "object argument must consume 'Net::Journyx::ObjectWithAttrs' role";
74 }
75  
76 0 $args{'object_type'} = $args{'object'}->object_type_for_attributes;
77 0 $args{'type_name'} = delete $args{'name'};
78  
79 0 my $response = $self->jx->soap->basic_call(
80 'getAttributeTypeRecordByName',
81 %args
82 );
83  
84 0 my $jx_class = $self->jx_record_class;
85 0 my $record = $response->{ $jx_class };
86 0 ▶ unless ( $record ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record) 0 0 0
87 0 die "No '$jx_class' in response ". Dumper($response);
88 }
89  
90 0 foreach my $k ( keys %$record ) {
91 0 ▶ if ( $k =~ /^_+(.*)$/ && !exists $record->{ $1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^_+(.*)$/ and not exists $record->{$1}) 0 0 0
Condition0%0/3
$k =~ /^_+(.*)$/ and not exists $record->{$1}
!ll&&!rl&&r
000
MC/DC0%0/2
$k =~ /^_+(.*)$/ and not exists $record->{$1}
$k =~ /^_+(.*)$/ not exists $record->{$1}
Truth table0%0/3
A and not(B)
A= $k =~ /^_+(.*)$/B= not exists $record->{$1}
ABresult
0X0
100
111
92 0 $record->{ $1 } = delete $record->{ $k };
93 }
94 }
95  
96 0 $self->jx_record( $record );
97 0 ▶ $self->_is_loaded(1) if $record->{'id_attr_type'};
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"id_attr_type"} 0 0 0
98  
99 0 return $self;
100 }
101  
102 0 ▶sub create {
Subroutine create: not called CC=4 SCAR=30.0
103 0 my $self = shift;
104 0 my %args = (
105 object => undef,
106 name => undef,
107 type => undef,
108 @_,
109 );
110  
111 0 ▶ unless ( blessed($args{'object'})
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")) 0 0 0
Condition0%0/6
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")
!ll&&!rl&&r
000
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object")
!ll&&!rl&&r
000
MC/DC0%0/3
builtin::blessed($args{"object"}) and $args{"object"}->isa("Moose::Object") and $args{"object"}->does("Net::Journyx::Object::WithAttrs")
builtin::blessed($args{"object"}) $args{"object"}->isa("Moose::Object") $args{"object"}->does("Net::Journyx::Object::WithAttrs")
Truth table0%0/4
A and B and C
A= builtin::blessed($args{"object"})B= $args{"object"}->isa("Moose::Object")C= $args{"object"}->does("Net::Journyx::Object::WithAttrs")
ABCresult
0XX0
10X0
1100
1111
112 && $args{'object'}->isa('Moose::Object')
113 && $args{'object'}->does('Net::Journyx::Object::WithAttrs')
114 ) {
115 0 die "object argument must consume 'Net::Journyx::Object::WithAttrs' role";
116 }
117  
118 0 my %create_args = ();
119  
120 0 $create_args{'object_type'} = $args{'object'}->object_type_for_attributes;
121 0 $create_args{'data_type'} = $args{'type'};
122 0 $create_args{'pname'} = $args{'name'};
123  
124 0 my $response = $self->jx->soap->basic_call(
125 'addAttributeType', %create_args
126 );
127  
128 # XXX: we created, but looks like we can not load by id :)
129 0 return $self->load( %args );
130 }
131  
132 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod undocumented
133 0 die "This object has no update method, it can be implemented,"
134 ." but use other methods at this point";
135 }
136  
137 # note that only admin can delete an attribute type
138 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
139 0 my $self = shift;
140 0 return $self->jx->soap->basic_call(
141 'deleteAttributeType',
142 id_attr_type => $self->id,
143 );
144 }
145  
146 0 ▶sub default_value {
Subroutine default_value: not called CC=4 SCAR=30.0
Pod undocumented
147 0 my $self = shift;
148 0 ▶ die "not loaded" unless $self->is_loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_loaded 0 0 0
149  
150 0 my $operation = 'getAttributeTypeDefaultValue';
151  
152 0 my $data_type = $self->data_type;
153 0 ▶ if ( $data_type eq 'NUMBER' || $data_type eq 'INTEGER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "NUMBER" or $data_type eq "INTEGER") 0 0 0
Condition0%0/3
$data_type eq "NUMBER" or $data_type eq "INTEGER"
l!l&&r!l&&!r
000
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"
ABresult
1X1
011
000
154 0 $operation .= ucfirst lc $data_type;
155 }
156  
157 0 return $self->jx->soap->basic_call(
158 $operation,
159 id_attr_type => $self->id,
160 );
161 }
162  
163 0 ▶sub set_default_value {
Subroutine set_default_value: not called CC=6 SCAR=37.4
Pod undocumented
164 0 my $self = shift;
165 0 my $value = shift;
166  
167 0 ▶ return $self->delete_default_value
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
168 unless defined $value and length $value;
169  
170 0 ▶ die "not loaded" unless $self->is_loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_loaded 0 0 0
171  
172 0 my $operation = 'setAttributeTypeDefaultValue';
173 0 my $data_type = $self->data_type;
174 0 ▶ if ( $data_type eq 'NUMBER' || $data_type eq 'INTEGER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "NUMBER" or $data_type eq "INTEGER") 0 0 0
Condition0%0/3
$data_type eq "NUMBER" or $data_type eq "INTEGER"
l!l&&r!l&&!r
000
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"
ABresult
1X1
011
000
175 0 $operation .= ucfirst lc $data_type;
176 }
177  
178 0 return $self->jx->soap->basic_call(
179 $operation,
180 id_attr_type => $self->id,
181 default_value => $value,
182 );
183 }
184  
185 0 ▶sub delete_default_value {
Subroutine delete_default_value: not called CC=2 SCAR=17.9
Pod undocumented
186 0 my $self = shift;
187 0 ▶ die "not loaded" unless $self->is_loaded;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_loaded 0 0 0
188  
189 0 return $self->jx->soap->basic_call(
190 'removeAttributeTypeDefaultValue',
191 id_attr_type => $self->id,
192 );
193 }
194  
195 5 1;
« Journyx/Object/WithAttrs.pm ↑ Summary Journyx/SOAP.pm »