SIAM/AccessScope.pm

filter: Statementstmt 98.2% 56 / 57 Branchbran 90.0% 9 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 93.4% 85 / 91 CC 9 SCAR 9.4
CC
9
Cov
95%
match_object
4.0
new
4.0
matches_all
2.0
CRAP 2.6
« SIAM/User.pm ↑ Summary SIAM/ServiceComponent.pm »
1 package SIAM::AccessScope;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use base 'SIAM::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use SIAM::ScopeMember;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 SIAM::AccessScope - access scope object class
13  
14 =head1 SYNOPSIS
15  
16  
17 =head1 INSTANCE METHODS
18  
19 =head2 new
20  
21 $scope = new SIAM::AccessScope($driver, {'siam.object.id' => $id})
22  
23 Instantiates a new object. The following object IDs are predefined and
24 are not fetched from the driver:
25  
26 =over 4
27  
28 =item * SIAM.SCOPE.ALL.CONTRACTS
29  
30 The access scope with the name I<AllContracts>. All contract objects are
31 implicitly included in it.
32  
33 =item * SIAM.SCOPE.ALL.ATTRIBUTES
34  
35 The access scope with the name I<AllAttributes>. All attribute names are
36 implicitly in it.
37  
38 =back
39  
40 =cut
41  
42 3 my %match_all_id =
43 ('SIAM.SCOPE.ALL.CONTRACTS' =>
44 {
45 'siam.scope.name' => 'AllContracts',
46 'siam.scope.applies_to' => 'SIAM::Contract',
47 },
48
49 'SIAM.SCOPE.ALL.ATTRIBUTES' =>
50 {
51 'siam.scope.name' => 'AllAttributes',
52 'siam.scope.applies_to' => 'SIAM::Attribute',
53 },
54 );
55  
56  
57 sub new
58 13 ▶{
Subroutine new: called CC=4 SCAR=13.9
Pod documented
59 13 my $class = shift;
60 13 my $driver = shift;
61 13 my $id = shift;
62
63 13 ▶ if( defined($id) and defined($match_all_id{$id}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $id and defined $match_all_id{$id}) { } 2 11 13
Condition66%2/3
defined $id and defined $match_all_id{$id}
!ll&&!rl&&r
0112
MC/DC50%1/2
defined $id and defined $match_all_id{$id}
defined $id defined $match_all_id{$id}
Truth table66%2/3
A and B
A= defined $idB= defined $match_all_id{$id}
ABresult
0X0
100
111
64 {
65 2 my $self = {};
66 2 bless $self, $class;
67  
68 2 $self->{'_attr'} = {'siam.object.id' => $id};
69 2 ▶ while( my($key, $val) = each %{$match_all_id{$id}} )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$match_all_id{$id};}) 4 2 6
70 {
71 4 $self->{'_attr'}{$key} = $val;
72 }
73  
74 2 return $self;
75 }
76 else
77 {
78 11 return $class->SUPER::new( $driver, $id );
79 }
80 }
81  
82  
83  
84 =head2 match_object
85  
86 Expects an object as an argument. Returns true if the object matches the scope.
87  
88 =cut
89  
90  
91 sub match_object
92 8 ▶{
Subroutine match_object: called CC=4 SCAR=13.9
Pod documented
93 8 my $self = shift;
94 8 my $obj = shift;
95  
96 # siam.scope.applies_to should match the object class
97 8 ▶ if( $obj->objclass ne $self->attr('siam.scope.applies_to') )
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->objclass ne $self->attr("siam.scope.applies_to")) 0 8 8
98 {
99 0 return undef;
100 }
101  
102 # check if we are one of the predefined scopes
103 8 ▶ if( defined($match_all_id{$self->id}) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match_all_id{$self->id}) 2 6 8
104 {
105 2 return 1;
106 }
107  
108 # check if object ID matches one of our members
109 6 my $members = $self->get_contained_objects
110 ('SIAM::ScopeMember',
111 {'match_attribute' => ['siam.scmember.object_id', [$obj->id()]]});
112  
113 6 ▶ if( scalar(@{$members}) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$members;} > 0) 4 2 6
114 {
115 4 return 1;
116 }
117
118 2 return undef;
119 }
120  
121  
122  
123 =head2 get_object_ids
124  
125 Returns arrayref with all object IDs to which this scope's members point to.
126  
127 =cut
128  
129  
130 sub get_object_ids
131 2 ▶{
Subroutine get_object_ids: called CC=2 SCAR=6.9
Pod documented
132 2 my $self = shift;
133
134 2 my $members = $self->get_contained_objects('SIAM::ScopeMember');
135  
136 2 my $ret = [];
137 2 foreach my $member (@{$members})
138 {
139 2 push(@{$ret}, $member->points_to);
140 }
141 2 return $ret;
142 }
143
144  
145  
146  
147 =head1 CLASS METHODS
148  
149  
150 =head2 matches_all
151  
152 Takes an ID of an SIAM::AccessScope object and the object class.
153 Returns true if it's a match-all scope for a given class.
154  
155 =cut
156  
157  
158 sub matches_all
159 4 ▶{
Subroutine matches_all: called CC=2 SCAR=7.0
Pod documented
160 4 my $class = shift;
161 4 my $id = shift;
162 4 my $objclass = shift;
163  
164 return( defined($match_all_id{$id}) and
165 4 ▶ $match_all_id{$id}{'siam.scope.applies_to'} eq $objclass );
Condition66%2/3
defined $match_all_id{$id} && $match_all_id{$id}{'siam.scope.applies_to'} eq $objclass
!ll&&!rl&&r
301
MC/DC50%1/2
defined $match_all_id{$id} && $match_all_id{$id}{'siam.scope.applies_to'} eq $objclass
defined $match_all_id{$id} $match_all_id{$id}{'siam.scope.applies_to'} eq $objclass
Truth table66%2/3
A && B
A= defined $match_all_id{$id}B= $match_all_id{$id}{'siam.scope.applies_to'} eq $objclass
ABresult
0X0
100
111
166 }
167  
168  
169  
170 # mandatory attributes
171  
172 3 my $mandatory_attributes =
173 [ 'siam.scope.name',
174 'siam.scope.applies_to' ];
175  
176 sub _mandatory_attributes
177 11 ▶{
Subroutine _mandatory_attributes: called CC=1 SCAR=0.0
178 11 return $mandatory_attributes;
179 }
180  
181 sub _manifest_attributes
182 1 ▶{
Subroutine _manifest_attributes: called CC=1 SCAR=0.0
183 1 my $ret = [];
184 1 push(@{$ret}, @{$mandatory_attributes},
185 1 @{ SIAM::ScopeMember->_manifest_attributes() });
186  
187 1 return $ret;
188 }
189  
190  
191 3 1;
192  
193 # Local Variables:
194 # mode: cperl
195 # indent-tabs-mode: nil
196 # cperl-indent-level: 4
197 # cperl-continued-statement-offset: 4
198 # cperl-continued-brace-offset: -4
199 # cperl-brace-offset: 0
200 # cperl-label-offset: -2
201 # End:
« SIAM/User.pm ↑ Summary SIAM/ServiceComponent.pm »