| 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/
defined $entry and $entry ne ""
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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/
defined $entry and $entry ne ""
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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/
defined $entry and $entry ne ""
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$month >= 1 and $month <= 12 or $month_array{lc $month}
$month >= 1 and $month <= 12
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}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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/
defined $entry and $entry ne ""
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/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if(validYear($date_a[0])) { #speed up needed!! | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
validYear($date_a[1]) and validMonth($date_a[0])
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])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
validYear($date_a[2]) and validMonth($date_a[1])
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])
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $field and $field ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $field = Ftree::StringUtils::trim($field); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if($field =~ /"(\S.+)"\s+"(\S.+)"\s+"(\S.+)"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return Ftree::Cemetery->new($1, $2, $3); | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if($field =~ /"(\S.+)"\s+"(\S.+)"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return Ftree::Cemetery->new($1, $2, undef); | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if($field =~ /"(\S.+)"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $field and $field ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 13 | $field = Ftree::StringUtils::trim($field); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | ▶ | if($field =~ /"(\S.+)"\s+"(\S.+)"/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | return \@places_array; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||