blib/lib/oEdtk/Field.pm untested

filter: Statementstmt 0.0% 0 / 19 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 31 CC 1 SCAR 6.9
CC
1
Cov
0%
new
2.0
process
2.0
get_name
2.0
CRAP 2.0
1 package oEdtk::Field;
2  
3 use strict;
4 use warnings;
5 our $VERSION = 2.1129;
6  
7 sub new {
8 my ( $class, $name, $len ) = @_;
9 my $field = {
10 name => $name,
11 len => $len,
12 };
13  
14 bless $field, $class;
15 return $field;
16 }
17  
18 sub process {
19 my ( $self, $data ) = @_;
20  
21 return $data;
22 }
23  
24 sub get_name {
25 my ($self) = @_;
26  
27 return $self->{'name'};
28 }
29  
30 sub set_name {
31 my ( $self, $name ) = @_;
32  
33 $self->{'name'} = $name;
34 }
35  
36 sub get_len {
37 my ($self) = @_;
38  
39 return $self->{'len'};
40 }
41  
42 1;
43  
44 =head1 NAME
45  
46 oEdtk::Field - abstract base class for fixed-width record fields
47  
48 =head1 SYNOPSIS
49  
50 use base 'oEdtk::Field';
51  
52 my $field = oEdtk::Field->new('NAME', 10);
53 print $field->get_name, "\n";
54 print $field->process('value'), "\n";
55  
56 =head1 DESCRIPTION
57  
58 The root of the field hierarchy used to describe the fixed-width records of an
59 Infinite flux. A field carries a name and a byte length and knows how to turn
60 the raw slice handed to it by C<oEdtk::Record> into a display value. The base
61 class returns the slice unchanged; subclasses (C<oEdtk::AddrField>,
62 C<oEdtk::DateField>, C<oEdtk::FPField>, C<oEdtk::SignedField>) override
63 L</process>.
64  
65 =head1 METHODS
66  
67 =head2 new
68  
69 my $field = oEdtk::Field->new($name, $len);
70  
71 Construct a field of name C<$name> and byte length C<$len>.
72  
73 =head2 process
74  
75 my $value = $field->process($data);
76  
77 Return the display value for the raw slice C<$data>. The base implementation is
78 the identity; subclasses override it.
79  
80 =head2 get_name
81  
82 my $name = $field->get_name;
83  
84 Return the field name.
85  
86 =head2 set_name
87  
88 $field->set_name($name);
89  
90 Set the field name.
91  
92 =head2 get_len
93  
94 my $len = $field->get_len;
95  
96 Return the field byte length.
97  
98 =head1 AUTHOR
99  
100 The oEdtk team.
101  
102 =cut