File Coverage

blib/lib/xDT/Record.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package xDT::Record;
2              
3 1     1   18 use v5.10;
  1         4  
4 1     1   6 use Moose;
  1         4  
  1         12  
5              
6 1     1   8223 use xDT::RecordType;
  1         6  
  1         388  
7              
8             =head1 NAME
9              
10             xDT::Record - A xDT record
11              
12             =head1 SYNOPSIS
13              
14             Instances of this module correspond to records (lines) in a xDT file.
15             They provide some methods to acces fields and record type metadata.
16              
17             use xDT::Record;
18              
19             my $record = xDT::Record->new($line);
20             say 'Value: '. $record->get_value();
21             say 'Length: '. $record->get_length();
22              
23             my $record_type = $record->get_record_type();
24              
25             =head1 ATTRIBUTES
26              
27             =head2 length
28              
29             The length of this record.
30              
31             =cut
32              
33             has 'length' => (
34             is => 'ro',
35             isa => 'Str',
36             required => 1,
37             reader => 'get_length',
38             documentation => q{The length of this records value (there are 2 extra symbols at the end of the string).},
39             );
40              
41             =head2 record_type
42              
43             This records record type.
44              
45             =cut
46              
47             has 'record_type' => (
48             is => 'rw',
49             isa => 'Maybe[xDT::RecordType]',
50             required => 1,
51             writer => 'set_record_type',
52             reader => 'get_record_type',
53             handles => {
54             get_accessor => 'get_accessor',
55             get_labels => 'get_labels',
56             get_id => 'get_id',
57             get_type => 'get_type',
58             get_max_length => 'get_length',
59             is_object_end => 'is_object_end',
60             },
61             documentation => q{The record type of this record.},
62             );
63              
64             =head2 value
65              
66             The value of this record.
67              
68             =cut
69              
70             has 'value' => (
71             is => 'ro',
72             isa => 'Maybe[Str]',
73             reader => 'get_value',
74             documentation => q{The value of this record as string.},
75             );
76              
77              
78             around BUILDARGS => sub {
79             my ($orig, $class, $line) = @_;
80              
81             my $value = substr($line, 7);
82             $value =~ s/\s*$//g;
83              
84             return $class->$orig(
85             length => substr($line, 0, 3),
86             record_type => undef,
87             value => $value,
88             );
89             };
90              
91             =head1 SUBROUTINES/METHODS
92              
93             =head2 get_length
94              
95             Returns the length of this record.
96              
97             =cut
98              
99             =head2 get_record_type
100              
101             Returns the record type of this record.
102              
103             =cut
104              
105             =head2 get_accessor
106              
107             Returns the accessor of the records record type.
108              
109             =cut
110              
111             =head2 get_labels
112              
113             Returns the labels of the records record type.
114              
115             =cut
116              
117             =head2 get_id
118              
119             Returns the id of the records record type.
120              
121             =cut
122              
123             =head2 get_type
124              
125             Returns the type of the records record type.
126              
127             =cut
128              
129             =head2 get_max_length
130              
131             Returns the maximum length of the records record type.
132              
133             =cut
134              
135             =head2 is_object_end
136              
137             Checks if the records record type is an end record.
138              
139             =cut
140              
141             =head2 get_value
142              
143             Returns the value of this record.
144              
145             =cut
146              
147             =head1 AUTHOR
148              
149             Christoph Beger, C<< <christoph.beger at medizin.uni-leipzig.de> >>
150              
151             =cut
152              
153             __PACKAGE__->meta->make_immutable;
154              
155             1; # End of xDT::Record