lib/Ftree/DataParsers/FieldValidatorParser.pm

filter: Statementstmt 72.8% 67 / 92 Branchbran 39.4% 15 / 38 Conditioncond 33.3% 14 / 42 MC/DCmcdc 4.3% 1 / 23 Subroutinesub 100% 17 / 17 Podpod 0.0% 0 / 10 totaltotal 51.3% 114 / 222 CC 35 SCAR 27.5
CC
35
Cov
56%
getDate
48.3
getCemetery
22.6
validMonth
6.5
CRAP 15.6
« lib/Ftree/Person.pm ↑ Summary blib/lib/Ftree/DataParsers/ExcelxFormat.pm »
1 package Ftree::DataParsers::FieldValidatorParser;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use version; our $VERSION = qv('2.3.41');
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use Ftree::Date::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Ftree::Place;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Ftree::Cemetery;
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 # use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
11 2 ▶use Ftree::StringUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 2 my %month_array = (
14 january => 1,
15 february => 2,
16 march => 3,
17 april => 4,
18 may => 5,
19 june => 6,
20 july => 7,
21 august => 8,
22 september => 9,
23 october => 10,
24 november => 11,
25 december => 12);
26
27
28 2 my $id_regexp = qr/\w+/;
29 33 ▶sub validIDEntry {
Subroutine validIDEntry: called CC=3 SCAR=14.2
Pod undocumented
30 33 my ( $entry ) = @_;
31 33 ▶ return defined $entry && $entry ne "" && $entry =~ m/$id_regexp/;
Condition33%2/6
defined $entry && $entry ne '' && $entry =~ /$id_regexp/
!ll&&!rl&&r
0033
defined $entry and $entry ne ""
!ll&&!rl&&r
0033
MC/DC0%0/3
defined $entry && $entry ne '' && $entry =~ /$id_regexp/
defined $entry $entry ne "" $entry =~ /$id_regexp/
Truth table25%1/4
A and B && C
A= defined $entryB= $entry ne ""C= $entry =~ /$id_regexp/
ABCresult
0XX0
10X0
1100
1111
32 }
33
34 2 my $email_regexp = qr/^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/;
35 2 ▶sub validEmail {
Subroutine validEmail: called CC=3 SCAR=14.2
Pod undocumented
36 2 my ( $entry ) = @_;
37 2 ▶ return defined $entry && $entry ne "" && $entry =~ m/$email_regexp/;
Condition33%2/6
defined $entry && $entry ne '' && $entry =~ /$email_regexp/
!ll&&!rl&&r
002
defined $entry and $entry ne ""
!ll&&!rl&&r
002
MC/DC0%0/3
defined $entry && $entry ne '' && $entry =~ /$email_regexp/
defined $entry $entry ne "" $entry =~ /$email_regexp/
Truth table25%1/4
A and B && C
A= defined $entryB= $entry ne ""C= $entry =~ /$email_regexp/
ABCresult
0XX0
10X0
1100
1111
38 }
39
40 2 my $url_regexp = qr/^https?:.*/;
41 7 ▶sub validURL {
Subroutine validURL: called CC=3 SCAR=14.2
Pod undocumented
42 7 my ( $entry ) = @_;
43 7 ▶ return defined $entry && $entry ne "" && $entry =~ m/$url_regexp/;
Condition33%2/6
defined $entry && $entry ne '' && $entry =~ /$url_regexp/
!ll&&!rl&&r
007
defined $entry and $entry ne ""
!ll&&!rl&&r
007
MC/DC0%0/3
defined $entry && $entry ne '' && $entry =~ /$url_regexp/
defined $entry $entry ne "" $entry =~ /$url_regexp/
Truth table25%1/4
A and B && C
A= defined $entryB= $entry ne ""C= $entry =~ /$url_regexp/
ABCresult
0XX0
10X0
1100
1111
44 }
45 2 ▶sub validYear {
Subroutine validYear: called CC=3 SCAR=13.6
Pod undocumented
46 2 my ($year) = @_;
47 2 my $this_year = 1900 + (localtime)[5];
48 2 ▶ if ($year > $this_year) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year > $this_year) 0 2 2
49 0 warn "Strange year: $year. Year cannot be larger than $this_year";
50 0 return;
51 }
52 2 ▶ if($year != int($year)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($year != int $year) 0 2 2
53 0 warn "Strange year: $year. Year should be an integer";
54 0 return;
55 }
56 2 return 1;
57 }
58
59 2 ▶sub validMonth {
Subroutine validMonth: called CC=4 SCAR=18.7
Pod undocumented
60 2 my ($month) = @_;
61 2 ▶ if ($month >=1 && $month <= 12 || $month_array{lc($month)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($month >= 1 and $month <= 12 or $month_array{lc $month}) 2 0 2
Condition33%2/6
$month >= 1 and $month <= 12 or $month_array{lc $month}
l!l&&r!l&&!r
200
$month >= 1 and $month <= 12
!ll&&!rl&&r
002
MC/DC0%0/3
$month >= 1 and $month <= 12 or $month_array{lc $month}
$month >= 1 $month <= 12 $month_array{lc $month}
Truth table20%1/5
A and B or C
A= $month >= 1B= $month <= 12C= $month_array{lc $month}
ABCresult
11X1
0X11
1011
0X00
1000
62 2 return 1;
63 }
64 0 warn "Strange month: $month. Month should be be between 1 and 12 or"
65 . " the name of the month in english";
66 0 return;
67 }
68
69 2 my $bool_regexp = qr/^[01]/;
70 29 ▶sub validBool {
Subroutine validBool: called CC=3 SCAR=14.2
Pod undocumented
71 29 my ($entry) = @_;
72 29 ▶ return defined $entry && $entry ne "" && $entry =~ m/$bool_regexp/;
Condition33%2/6
defined $entry && $entry ne '' && $entry =~ /$bool_regexp/
!ll&&!rl&&r
0029
defined $entry and $entry ne ""
!ll&&!rl&&r
0029
MC/DC0%0/3
defined $entry && $entry ne '' && $entry =~ /$bool_regexp/
defined $entry $entry ne "" $entry =~ /$bool_regexp/
Truth table25%1/4
A and B && C
A= defined $entryB= $entry ne ""C= $entry =~ /$bool_regexp/
ABCresult
0XX0
10X0
1100
1111
73 }
74
75 2 ▶sub getDate {
Subroutine getDate: called CC=11 SCAR=38.8
Pod undocumented
76 2 my ($date) = @_;
77 2 my @date_a = split( '/', $date );
78 2 ▶ if(scalar @date_a == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (scalar @date_a == 1) { } 0 2 2
elsif (scalar @date_a == 2) { } 0 2 2
elsif (scalar @date_a == 3) { } 2 0 2
79 0 ▶ if(validYear($date_a[0])) { #speed up needed!!
Branch: 1 branch
BranchTrueFalseTotal
if (validYear($date_a[0])) { } 0 0 0
80 0 return Ftree::Date::Tiny->new(year => $date_a[0]);
81 } else {
82 0 return;
83 }
84 }
85 elsif(scalar @date_a == 2) {
86 0 $date_a[0] = lc($date_a[0]);
87 0 ▶ if(validYear($date_a[1]) && validMonth($date_a[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (validYear($date_a[1]) and validMonth($date_a[0])) { } 0 0 0
Condition0%0/3
validYear($date_a[1]) and validMonth($date_a[0])
!ll&&!rl&&r
000
MC/DC0%0/2
validYear($date_a[1]) and validMonth($date_a[0])
validYear($date_a[1]) validMonth($date_a[0])
Truth table0%0/3
A and B
A= validYear($date_a[1])B= validMonth($date_a[0])
ABresult
0X0
100
111
88 0 ▶ return Ftree::Date::Tiny->new(month => defined $month_array{$date_a[0]} ? $month_array{$date_a[0]} : $date_a[0],
Branch: 1 branch
BranchTrueFalseTotal
defined $month_array{$date_a[0]} ? : 0 0 0
89 year => $date_a[1]);
90 } else {
91 0 return;
92 }
93
94 }
95 elsif(scalar @date_a == 3) {
96 2 $date_a[1] = lc($date_a[1]);
97 2 ▶ if(validYear($date_a[2]) && validMonth($date_a[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (validYear($date_a[2]) and validMonth($date_a[1])) { } 2 0 2
Condition33%1/3
validYear($date_a[2]) and validMonth($date_a[1])
!ll&&!rl&&r
002
MC/DC0%0/2
validYear($date_a[2]) and validMonth($date_a[1])
validYear($date_a[2]) validMonth($date_a[1])
Truth table33%1/3
A and B
A= validYear($date_a[2])B= validMonth($date_a[1])
ABresult
0X0
100
111
98 return Ftree::Date::Tiny->new(day => $date_a[0],
99 2 ▶ month => defined $month_array{$date_a[1]} ? $month_array{$date_a[1]} : $date_a[1],
Branch: 1 branch
BranchTrueFalseTotal
defined $month_array{$date_a[1]} ? : 0 2 2
100 year => $date_a[2]);
101 }
102 else {
103 0 return;
104 }
105 }
106 else {
107 0 return;
108 }
109 }
110 15 ▶sub getCemetery {
Subroutine getCemetery: called CC=6 SCAR=31.2
Pod undocumented
111 15 my ($field) = @_;
112 15 ▶ if(defined $field && $field ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field and $field ne "") 0 15 15
Condition33%1/3
defined $field and $field ne ""
!ll&&!rl&&r
1500
MC/DC0%0/2
defined $field and $field ne ""
defined $field $field ne ""
Truth table33%1/3
A and B
A= defined $fieldB= $field ne ""
ABresult
0X0
100
111
113 0 $field = Ftree::StringUtils::trim($field);
114 0 ▶ if($field =~ /"(\S.+)"\s+"(\S.+)"\s+"(\S.+)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /"(\S.+)"\s+"(\S.+)"\s+"(\S.+)"/) 0 0 0
115 0 return Ftree::Cemetery->new($1, $2, $3);
116 }
117 0 ▶ if($field =~ /"(\S.+)"\s+"(\S.+)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /"(\S.+)"\s+"(\S.+)"/) 0 0 0
118 0 return Ftree::Cemetery->new($1, $2, undef);
119 }
120 0 ▶ if($field =~ /"(\S.+)"/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /"(\S.+)"/) 0 0 0
121 0 return Ftree::Cemetery->new($1, undef, undef);
122 }
123 0 warn "Nonvalid cemetery: ". $field . ". It should be like \"Hungary\" \"Budapest\" \"Farkasréti\"";
124 }
125 15 return;
126 }
127 23 ▶sub getPlace {
Subroutine getPlace: called CC=5 SCAR=16.6
Pod undocumented
128 23 my ($field) = @_;
129 23 ▶ if(defined $field && $field ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $field and $field ne '') { } 13 10 23
Condition66%2/3
defined $field and $field ne ""
!ll&&!rl&&r
10013
MC/DC50%1/2
defined $field and $field ne ""
defined $field $field ne ""
Truth table66%2/3
A and B
A= defined $fieldB= $field ne ""
ABresult
0X0
100
111
130 13 $field = Ftree::StringUtils::trim($field);
131 13 ▶ if($field =~ /"(\S.+)"\s+"(\S.+)"/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field =~ /"(\S.+)"\s+"(\S.+)"/) { } 12 1 13
elsif ($field =~ /"(\S.+)"/) { } 1 0 1
132 12 return Ftree::Place->new($1, $2);
133 }
134 elsif($field =~ /"(\S.+)"/) {
135 1 return Ftree::Place->new($1, undef);
136 }
137 else {
138 0 warn "Nonvalid place: ". $field . ". It should be like \"Hungary\" \"Budapest\" ";
139 0 return;
140 }
141 }
142 else {
143 10 return;
144 }
145 }
146
147 6 ▶sub getPlacesArray {
Subroutine getPlacesArray: called CC=3 SCAR=11.0
Pod undocumented
148 6 my ($places_string) = @_;
149 6 my @pair_array = split(/,/, $places_string);
150 6 my @places_array;
151 6 for (@pair_array) {
152 8 my $a_place = getPlace($_);
153 8 ▶ push @places_array, $a_place if(defined $a_place);
Branch: 1 branch
BranchTrueFalseTotal
if defined $a_place 8 0 8
154 }
155 6 return \@places_array;
156 }
157
158
159 2 1;
« lib/Ftree/Person.pm ↑ Summary blib/lib/Ftree/DataParsers/ExcelxFormat.pm »