File Coverage

blib/lib/xDT/Object.pm
Criterion Covered Total %
statement 3 5 60.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 5 7 71.4


line stmt bran cond sub pod time code
1             package xDT::Object;
2              
3 1     1   3038 use v5.10;
  1         4  
4 1     1   178 use Moose;
  0            
  0            
5             use namespace::autoclean;
6             use Carp;
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.00
15              
16             =cut
17              
18             our $VERSION = '1.00';
19              
20              
21             =head1 SYNOPSIS
22              
23             Instances should be used to aggregate records for a single patient.
24             Each object should starts and ends 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->addRecord(@records);
31              
32             say 'Patient number: '. $object->getValue('patientNumber');
33             say 'Birthdate: '. $object->getValue('birthdate');
34              
35             =head1 ATTRIBUTES
36              
37             =head2 records
38             An ArrayRef to xDT::Record instances.
39             =cut
40              
41             has 'records' => (
42             is => 'rw',
43             isa => 'ArrayRef[xDT::Record]',
44             traits => ['Array'],
45             default => sub { [ ] },
46             handles => {
47             getRecords => 'elements',
48             addRecord => 'push',
49             mapRecords => 'map',
50             recordCount => 'count',
51             sortedRecords => 'sort',
52             nextRecord => 'shift',
53             },
54             documentation => 'A collection of logical associated records.',
55             );
56              
57             =head1 SUBROUTINES/METHODS
58              
59             =head2 isEmpty
60             Checks if this object has any records.
61             =cut
62              
63             sub isEmpty {
64             my $self = shift;
65              
66             return $self->recordCount == 0;
67             }
68              
69             =head2 get($accessor)
70             This function returns all records of the object with have the given accessor.
71             =cut
72              
73             sub get {
74             my $self = shift;
75             my $accessor = shift // croak('Error: parameter $accessor missing.');
76              
77             return grep { $_->getAccessor() eq $accessor } $self->getRecords();
78             }
79              
80             =head2 getValue($accessor)
81             In contrast to xDT::Object->get(), this function returns the values of records, returned by xDT::Object->get().
82             =cut
83              
84             sub getValue {
85             my $self = shift;
86             my $accessor = shift // croak('Error: parameter $accessor missing.');
87             my @records = $self->get($accessor);
88            
89             return undef unless @records;
90             return map { $_->getValue() } @records;
91             }
92              
93             =head2 getRecords
94             Corresponse to the elements function.
95             =cut
96              
97             =head2 addRecord
98             Corresponse to the push function.
99             =cut
100              
101             =head2 mapRecords
102             Corresponse to the map function.
103             =cut
104              
105             =head2 recordCount
106             Correpsonse to the count function.
107             =cut
108              
109             =head2 sortedRecords
110             Corresponse to the sort function.
111             =cut
112              
113             =head2 nextRecord
114             Corresponse to the shift function.
115             =cut
116              
117             =head1 AUTHOR
118              
119             Christoph Beger, C<< >>
120              
121             =head1 BUGS
122              
123             Please report any bugs or feature requests to C, or through
124             the web interface at L. I will be notified, and then you'll
125             automatically be notified of progress on your bug as I make changes.
126              
127              
128              
129              
130             =head1 SUPPORT
131              
132             You can find documentation for this module with the perldoc command.
133              
134             perldoc xDT::Object
135              
136              
137             You can also look for information at:
138              
139             =over 4
140              
141             =item * RT: CPAN's request tracker (report bugs here)
142              
143             L
144              
145             =item * AnnoCPAN: Annotated CPAN documentation
146              
147             L
148              
149             =item * CPAN Ratings
150              
151             L
152              
153             =item * Search CPAN
154              
155             L
156              
157             =back
158              
159              
160             =head1 ACKNOWLEDGEMENTS
161              
162              
163             =head1 LICENSE AND COPYRIGHT
164              
165             Copyright 2017 Christoph Beger.
166              
167             This program is released under the following license: MIT
168              
169              
170             =cut
171              
172             __PACKAGE__->meta->make_immutable;
173              
174             1; # End of xDT::Object