File Coverage

blib/lib/xDT/Object.pm
Criterion Covered Total %
statement 17 28 60.7
branch 1 2 50.0
condition 2 8 25.0
subroutine 5 8 62.5
pod 5 5 100.0
total 30 51 58.8


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