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