Object.pm

filter: Statementstmt 66.6% 22 / 33 Branchbran 50.0% 1 / 2 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 6 / 9 Podpod 100% 5 / 5 totaltotal 59.0% 36 / 61 SCAR 21.6
CC
6
Cov
58%
get_every_record
6.0
get_every_value
6.0
get_value
3.1
CRAP 8.6
« Parser.pm ↑ Summary RecordType.pm »
1 package xDT::Object;
2  
3 2 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use xDT::Record;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 xDT::Object - Instances of this module are collections of xDT records.
11  
12 =head1 VERSION
13  
14 Version 1.06
15  
16 =cut
17  
18 2 our $VERSION = '1.06';
19  
20  
21 =head1 SYNOPSIS
22  
23 Instances should be used to aggregate records for a single patient.
24 Each object should start and end with respective record types of the used xDT version.
25  
26 use xDT::Object;
27  
28 my @records = (); # should be an array of xDT::Record instances
29 my $object = xDT::Object->new();
30 $object->add_record(@records);
31  
32 say 'Patient number: '. $object->get_value('patient_number');
33 say 'Birthdate: '. $object->get_value('birthdate');
34  
35 =head1 ATTRIBUTES
36  
37 =head2 records
38  
39 An ArrayRef to xDT::Record instances.
40  
41 =cut
42  
43 has 'records' => (
44 is => 'rw',
45 isa => 'ArrayRef[xDT::Record]',
46 traits => ['Array'],
47 3 ▶ default => sub { [ ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
48 2 handles => {
49 get_records => 'elements',
50 add_record => 'push',
51 map_records => 'map',
52 record_count => 'count',
53 sorted_records => 'sort',
54 next_record => 'shift',
55 },
56 documentation => q{A collection of logical associated records.},
57 );
58  
59 =head1 SUBROUTINES/METHODS
60  
61 =head2 is_empty
62  
63 Checks if this object has any records.
64  
65 =cut
66  
67 sub is_empty {
68 0 ▶ my $self = shift;
Subroutine is_empty: not called CC=1 SCAR=6.9
Pod documented
69  
70 0 return $self->record_count == 0;
71 }
72  
73 =head2 get_every_record($accessor)
74  
75 Returns all records as arrayref, which have the given accessor.
76  
77 =cut
78  
79 sub get_every_record {
80 0 ▶ my $self = shift;
Subroutine get_every_record: not called CC=2 SCAR=17.9
Pod documented
81 0 ▶ my $accessor = shift // die 'Error: parameter $accessor missing.';
Condition0%0/2
shift() // die("Error: parameter \$accessor missing.")
l!l
00
MC/DC0%0/1
shift() // die("Error: parameter \$accessor missing.")
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
82 0 return [ grep { $_->get_accessor() eq $accessor } $self->get_records() ];
83 }
84  
85 =head2 get_record($accessor)
86  
87 Returns the first record with the given accessor, if there are any, else undef.
88  
89 =cut
90  
91 sub get_record {
92 3 ▶ my $self = shift;
Subroutine get_record: called CC=2 SCAR=7.0
Pod documented
93 3 ▶ my $accessor = shift // die 'Error: parameter $accessor missing.';
Condition50%1/2
shift() // die("Error: parameter \$accessor missing.")
l!l
30
MC/DC0%0/1
shift() // die("Error: parameter \$accessor missing.")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
94 3 my ($record) = grep { $_->get_accessor() eq $accessor } $self->get_records();
95  
96 3 return $record;
97 }
98  
99 =head2 get_every_value($accessor)
100  
101 Returns the values of all records as arrayref, which have the given accessor.
102  
103 =cut
104  
105 sub get_every_value {
106 0 ▶ my $self = shift;
Subroutine get_every_value: not called CC=2 SCAR=17.9
Pod documented
107 0 ▶ my $accessor = shift // die 'Error: parameter $accessor missing.';
Condition0%0/2
shift() // die("Error: parameter \$accessor missing.")
l!l
00
MC/DC0%0/1
shift() // die("Error: parameter \$accessor missing.")
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
108 0 my $records = $self->get_every_record($accessor);
109  
110 0 return [ map { $_->get_value } @$records ];
111 }
112  
113 =head2 get_value($accessor)
114  
115 Returns the value of the first record with the given accessor, if there are any, else undef.
116  
117 =cut
118  
119 sub get_value {
120 3 ▶ my $self = shift;
Subroutine get_value: called CC=3 SCAR=11.4
Pod documented
121 3 ▶ my $accessor = shift // die 'Error: parameter $accessor missing.';
Condition50%1/2
shift() // die("Error: parameter \$accessor missing.")
l!l
30
MC/DC0%0/1
shift() // die("Error: parameter \$accessor missing.")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
122 3 my $record = $self->get_record($accessor);
123  
124 3 ▶ return $record ? $record->get_value : undef;
Branch: 1 branch
BranchTrueFalseTotal
$record ? : 3 0 3
125 }
126  
127 =head2 get_records
128  
129 Corresponse to the elements function.
130  
131 =cut
132  
133 =head2 add_record
134  
135 Corresponse to the push function.
136  
137 =cut
138  
139 =head2 map_records
140  
141 Corresponse to the map function.
142  
143 =cut
144  
145 =head2 record_count
146  
147 Correpsonse to the count function.
148  
149 =cut
150  
151 =head2 sorted_records
152  
153 Corresponse to the sort function.
154  
155 =cut
156  
157 =head2 next_record
158  
159 Corresponse to the shift function.
160  
161 =cut
162  
163 =head1 AUTHOR
164  
165 Christoph Beger, C<< <christoph.beger at medizin.uni-leipzig.de> >>
166  
167 =cut
168  
169 2 __PACKAGE__->meta->make_immutable;
170  
171 2 1; # End of xDT::Object
« Parser.pm ↑ Summary RecordType.pm »