RecordType.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 95.6% 44 / 46 SCAR 16.1
CC
5
Cov
97%
build_from_arrayref
4.0
_check_id
2.0
BEGIN
1.0
CRAP 5.0
« Object.pm ↑ Summary Record.pm »
1 package xDT::RecordType;
2  
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 xDT::RecordType - The record type of a xDT record.
9  
10 =head1 VERSION
11  
12 Version 1.06
13  
14 =cut
15  
16 4 our $VERSION = '1.06';
17  
18  
19 =head1 SYNOPSIS
20  
21 Quick summary of what the module does.
22  
23 Perhaps a little code snippet.
24  
25 use xDT::RecordType;
26  
27 my $record_type = xDT::RecordType->new($id);
28 # or
29 my $record_type = xDT::RecordType->new($id, $config_file);
30  
31 say $record_type->get_labels()->{en};
32 say $record_type->get_accessor();
33  
34 =head1 CONSTANTS
35  
36 =head2 LENGTH
37  
38 The maximum length of a record type identifier.
39  
40 =head2 END_RECORD_ID
41  
42 ID of records at the end of an object.
43  
44 =cut
45  
46 use constant {
47 4 LENGTH => 4,
48 END_RECORD_ID => 8003,
49 4 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 =head1 ATTRIBUTES
52  
53 =head2 id
54  
55 Unique identifier of this record type.
56  
57 =cut
58  
59 4 has id => (
60 is => 'ro',
61 isa => 'Str',
62 required => 1,
63 reader => 'get_id',
64 trigger => \&_check_id,
65 documentation => q{Unique identifier of this record type.},
66 );
67  
68 =head2 labels
69  
70 The human readable labels of this record type. Language is used as key value.
71  
72 =cut
73  
74 4 has labels => (
75 is => 'ro',
76 isa => 'Maybe[HashRef[Str]]',
77 reader => 'get_labels',
78 documentation => q{The human readable labels of this record type. Language is used as key value.},
79 );
80  
81 =head2 accessor
82  
83 Short string for easy access to this record via xDT::Object.
84  
85 =cut
86  
87 has accessor => (
88 is => 'ro',
89 isa => 'Str',
90 required => 1,
91 lazy => 1,
92 reader => 'get_accessor',
93 1 ▶ default => sub { shift->get_id },
Subroutine __ANON__: called CC=1 SCAR=0.0
94 4 documentation => q{Short string for easy access to this record via xDT::Object.},
95 );
96  
97 =head2 length
98  
99 Max length of this record type.
100  
101 =cut
102  
103 4 has length => (
104 is => 'ro',
105 isa => 'Maybe[Str]',
106 reader => 'get_length',
107 documentation => q{Max length of this record type.},
108 );
109  
110 =head2 type
111  
112 Corresponds to xDT record type string.
113  
114 =cut
115  
116 4 has type => (
117 is => 'ro',
118 isa => 'Maybe[Str]',
119 reader => 'get_type',
120 documentation => q{Corresponds to xDT record type string.},
121 );
122  
123 =head1 SUBROUTINES/METHODS
124  
125 =head2 is_object_end
126  
127 Checks if this record type is an ending record
128  
129 =cut
130  
131 sub is_object_end {
132 38 ▶ my $self = shift;
Subroutine is_object_end: called CC=1 SCAR=0.0
Pod documented
133  
134 38 return $self->get_id == END_RECORD_ID;
135 }
136  
137 =head2 get_id
138  
139 Returns the id of this record type.
140  
141 =cut
142  
143 =head2 get_labels
144  
145 Returns the labels of this record type.
146  
147 =cut
148  
149 =head2 get_accessor
150  
151 Returns the accessor of this record type.
152  
153 =cut
154  
155 =head2 get_length
156  
157 Returns the maximum length of this recourd type.
158  
159 =cut
160  
161 =head2 build_from_arrayref
162  
163 Constructs a C<RecordType> from a arrayref containing configurations.
164 This method will propagate the hashref, that contains the provided id, to the C<new> method.
165  
166 =cut
167  
168 sub build_from_arrayref {
169 36 ▶ my $id = shift // die 'Error: parameter $id missing.';
Subroutine build_from_arrayref: called CC=4 SCAR=13.9
Pod documented
Condition50%1/2
shift() // die("Error: parameter \$id missing.")
l!l
036
MC/DC0%0/1
shift() // die("Error: parameter \$id missing.")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
170 36 my $arrayref = shift;
171 36 my $config;
172  
173 36 ▶ ($config) = grep { $_->{id} eq $id } @$arrayref
Branch: 1 branch
BranchTrueFalseTotal
if $arrayref 24 12 36
174 if ($arrayref);
175  
176 36 ▶ $config = { id => $id, accessor => $id } unless ($config);
Branch: 1 branch
BranchTrueFalseTotal
unless $config 14 22 36
177  
178 36 return xDT::RecordType->new($config);
179 }
180  
181  
182 sub _check_id {
183 42 ▶ my ($self, $id) = @_;
Subroutine _check_id: called CC=2 SCAR=6.9
184  
185 42 ▶ die(sprintf("Error: attribute 'id' has length %d (should be %d).", length $id, LENGTH))
Branch: 1 branch
BranchTrueFalseTotal
unless length $id == 4 1 41 42
186 unless (length $id == LENGTH);
187 }
188  
189 =head1 AUTHOR
190  
191 Christoph Beger, C<< <christoph.beger at medizin.uni-leipzig.de> >>
192  
193 =cut
194  
195 4 __PACKAGE__->meta->make_immutable;
196  
197 4 1; # End of xDT::RecordType
« Object.pm ↑ Summary Record.pm »