TigerLine/Record/Accessor.pm

filter: Statementstmt 88.8% 48 / 54 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 9 / 9 Podpod 75.0% 3 / 4 totaltotal 73.0% 73 / 100 CC 13 SCAR 20.3
CC
13
Cov
75%
set
15.1
mk_accessor
5.7
input_check
2.0
CRAP 7.6
« TigerLine/Record.pm ↑ Summary TigerLine/Record/Parser.pm »
1 package Geo::TigerLine::Record::Accessor;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $VERSION = '0.03';
6  
7 1 ▶use base qw(Class::Accessor Class::Data::Inheritable);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Carp::Assert;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 =pod
13  
14 =head1 NAME
15  
16 Geo::TigerLine::Record::Accessor - Accessor generation for Geo::TigerLine::Record::*
17  
18 =head1 SYNOPSIS
19  
20 package Geo::TigerLine::Record::1001001;
21  
22 use base qw(Geo::TigerLine::Record::Accessor);
23  
24 # Generate accessors for each field of the record.
25 foreach my $def (values %{__PACKAGE__->Fields}) {
26 __PACKAGE__->mk_accessor($def);
27 }
28  
29 # Turn off input checks, makes inserting raw data faster.
30 __PACKAGE__->input_checks(0);
31  
32 =head1 DESCRIPTION
33  
34 Allows accessor generation for all the fields of each TIGER/Line record type.
35 You probabably shouldn't be here.
36  
37 This is a subclass of Class::Accessor.
38  
39 =cut
40  
41 #'#
42 {
43 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 44 ▶ sub mk_accessor {
Subroutine mk_accessor: called CC=5 SCAR=17.4
Pod undocumented
46 44 my($self, $def) = @_;
47
48 44 ▶ my $class = ref $self || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
0440
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
49 44 my $field = $def->{field};
50  
51 44 ▶ if( $field eq 'DESTROY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "DESTROY") 0 44 44
52 0 require Carp;
53 0 &Carp::carp("Having a data accessor named DESTROY in ".
54 "'$class' is unwise.");
55 }
56  
57 44 my $accessor = $self->make_accessor($def);
58 44 my $alias = "_${field}_accessor";
59
60 44 *{$class."\:\:$field"} = $accessor
61 44 ▶ unless defined &{$class."\:\:$field"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$class . "::$field";} 44 0 44
62
63 44 *{$class."\:\:$alias"} = $accessor
64 44 ▶ unless defined &{$class."\:\:$alias"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$class . "::$alias";} 44 0 44
65 }
66 }
67  
68  
69 1 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
70 116 my($self, $def) = @_;
71 116 return $self->{$def->{field}};
72 }
73  
74  
75 1 ▶sub set {
Subroutine set: called CC=8 SCAR=27.2
Pod documented
76 1 my($self, $def, $val) = @_;
77  
78 1 ▶ if( $self->input_check ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->input_check) 1 0 1
79 1 ▶ if ( $val !~ /\S/ && !$def->{bv} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val =~ /\S/ or $def->{"bv"}) 0 1 1
Condition33%1/3
$val =~ /\S/ or $def->{"bv"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$val =~ /\S/ or $def->{"bv"}
$val =~ /\S/ $def->{"bv"}
Truth table33%1/3
A or B
A= $val =~ /\S/B= $def->{"bv"}
ABresult
1X1
011
000
80 0 Carp::carp("$def->{field} is not allowed to be blank.");
81 }
82
83 1 ▶ if ( $val =~ /[^\d+\-]/ && $def->{type} eq 'N' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /[^\d+\-]/ and $def->{"type"} eq "N") 0 1 1
Condition33%1/3
$val =~ /[^\d+\-]/ and $def->{"type"} eq "N"
!ll&&!rl&&r
100
MC/DC0%0/2
$val =~ /[^\d+\-]/ and $def->{"type"} eq "N"
$val =~ /[^\d+\-]/ $def->{"type"} eq "N"
Truth table33%1/3
A and B
A= $val =~ /[^\d+\-]/B= $def->{"type"} eq "N"
ABresult
0X0
100
111
84 0 Carp::carp("$def->{field} can contain only numbers. ('$val')");
85 }
86
87 1 ▶ if ( $val =~ /[^A-Z'\/()&\d+\-\]\[\# ]/i ) { #']) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ m([^A-Z'/()&\d+\-\]\[\# ])i) 0 1 1
88 0 Carp::carp("$def->{field} can only contain alphanumeric ".
89 "characters. ('$val')");
90 }
91
92 1 ▶ if ( length $val > $def->{len} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $val > $def->{"len"}) 0 1 1
93 0 Carp::carp("$def->{field} can only be $def->{len} characters long. ".
94 "('$val')");
95 }
96 }
97  
98 1 $self->{$def->{field}} = $val;
99 }
100  
101 =head2 Additional Methods
102  
103 =over 4
104  
105 =item B<input_check>
106  
107 Class->input_check($true_or_false);
108 $true_or_false = Class->input_check;
109 $true_or_false = $obj->input_check;
110  
111 If true, turns on the input checks done each time a value is set.
112 False turns them off.
113  
114 This setting is inherited.
115  
116 By default, the checks are on.
117  
118 =cut
119  
120 #'#
121 1 __PACKAGE__->mk_classdata('__Input_Check');
122 1 __PACKAGE__->input_check(1); # Start out doing the checks.
123 2 ▶sub input_check {
Subroutine input_check: called CC=2 SCAR=6.9
Pod documented
124 2 my($class) = shift;
125 2 my($check) = @_;
126  
127 2 ▶ if( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 1 2
128 1 assert( !ref $class ) if DEBUG;
129 1 $class->__Input_Check($check);
130 }
131 else {
132 1 $check = $class->__Input_Check;
133 }
134  
135 2 return $check;
136 }
137  
138 =pod
139  
140 =back
141  
142 =head1 AUTHOR
143  
144 Michael G Schwern <schwern@pobox.com>
145  
146 =head1 SEE ALSO
147  
148 L<Class::Accessor>, L<Geo::TigerLine::Record>
149  
150 =cut
151  
152  
153 1 return 'Bloody balls up';
« TigerLine/Record.pm ↑ Summary TigerLine/Record/Parser.pm »