| 1 | package DBIx::Class::Validation::Structure; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008_005; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.15'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Email::Valid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use HTML::TagFilter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use base qw/DBIx::Class/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | sub validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=36 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | my @check_columns = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $check_columns = { map{ $_ => 1 } @check_columns } || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
{map({$_, 1;} @check_columns)} || {}
MC/DC0%0/1
{map({$_, 1;} @check_columns)} || {}
{map({$_, 1;} @check_columns)}
Truth table50%1/2
A
A= {map({$_, 1;} @check_columns)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | my %data = $self->get_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my $columns = $source->columns_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | my ($error, @error_list, $stmt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | for my $column ( keys %$columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 36 | ▶ | if ( ( not keys %$check_columns ) or $check_columns->{$column} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not keys %$check_columns or $check_columns->{$column}
MC/DC0%0/2
not keys %$check_columns or $check_columns->{$column}
not keys %$check_columns
$check_columns->{$column}
Truth table33%1/3
not(A) or B
A= not keys %$check_columnsB= $check_columns->{$column}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 36 | ▶ | if ($columns->{$column}{validation_function} and ref $columns->{$column}{validation_function} eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$columns->{$column}{"validation_function"} and ref $columns->{$column}{"validation_function"} eq "CODE"
MC/DC0%0/2
$columns->{$column}{"validation_function"} and ref $columns->{$column}{"validation_function"} eq "CODE"
$columns->{$column}{"validation_function"}
ref $columns->{$column}{"validation_function"} eq "CODE"
Truth table33%1/3
A and B
A= $columns->{$column}{"validation_function"}B= ref $columns->{$column}{"validation_function"} eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ($data{$column}, $error) = $columns->{$column}{validation_function}( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | info => $columns->{$column}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | value => $data{$column}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | data => \%data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | self => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 36 | ▶ | my $mand = (defined $columns->{$column}{is_nullable} and $columns->{$column}{is_nullable} == 1 or ( defined $columns->{$column}{is_auto_increment} and $columns->{$column}{is_auto_increment} == 1 ) ) ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1 or defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1
defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
MC/DC50%2/4
defined $columns->{$column}{"is_nullable"} and $columns->{$column}{"is_nullable"} == 1 or defined $columns->{$column}{"is_auto_increment"} and $columns->{$column}{"is_auto_increment"} == 1
defined $columns->{$column}{"is_nullable"}
$columns->{$column}{"is_nullable"} == 1
defined $columns->{$column}{"is_auto_increment"}
$columns->{$column}{"is_auto_increment"} == 1
Truth table42%3/7
A and B or C and D
A= defined $columns->{$column}{"is_nullable"}B= $columns->{$column}{"is_nullable"} == 1C= defined $columns->{$column}{"is_auto_increment"}D= $columns->{$column}{"is_auto_increment"} == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 36 | ▶ | my $val_type = (defined $columns->{$column}{val_override}) ? $columns->{$column}{val_override} : $columns->{$column}{data_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 36 | ▶ | if ($val_type eq 'email') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 6 | ($data{$column}, $error) = _val_email( $mand, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ▶ | } elsif ($val_type eq 'varchar' or $val_type eq 'text') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$val_type eq "varchar" or $val_type eq "text"
MC/DC50%1/2
$val_type eq "varchar" or $val_type eq "text"
$val_type eq "varchar"
$val_type eq "text"
Truth table66%2/3
A or B
A= $val_type eq "varchar"B= $val_type eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 24 | ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } elsif ($val_type eq 'password') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ($data{$column}, $error) = _val_password( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ($val_type eq 'selected') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($columns->{$column}{data_type} eq 'varchar' or $columns->{$column}{data_type} eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$columns->{$column}{"data_type"} eq "varchar" or $columns->{$column}{"data_type"} eq "text"
MC/DC0%0/2
$columns->{$column}{"data_type"} eq "varchar" or $columns->{$column}{"data_type"} eq "text"
$columns->{$column}{"data_type"} eq "varchar"
$columns->{$column}{"data_type"} eq "text"
Truth table0%0/3
A or B
A= $columns->{$column}{"data_type"} eq "varchar"B= $columns->{$column}{"data_type"} eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ($data{$column}, $error) = _val_text( 0, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ($data{$column}, $error) = _val_int( 0, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ($data{$column}, $error) = _val_selected( $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ▶ | } elsif ($val_type eq 'integer' or $val_type =~ /int/g) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$val_type eq "integer" or $val_type =~ /int/g
MC/DC0%0/2
$val_type eq "integer" or $val_type =~ /int/g
$val_type eq "integer"
$val_type =~ /int/g
Truth table33%1/3
A or B
A= $val_type eq "integer"B= $val_type =~ /int/g
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | ($data{$column}, $error) = _val_int( $mand, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } elsif ($val_type eq 'number') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ($data{$column}, $error) = _val_number( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # If the column is auto_increment and there is no value set, set it to undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # @TODO decide if this should be deleted all together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 36 | ▶ | $data{$column} = undef if $columns->{$column}{is_auto_increment} and not $data{$column}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$columns->{$column}{"is_auto_increment"} and not $data{$column}
MC/DC100%2/2
$columns->{$column}{"is_auto_increment"} and not $data{$column}
$columns->{$column}{"is_auto_increment"}
not $data{$column}
Truth table100%3/3
A and not(B)
A= $columns->{$column}{"is_auto_increment"}B= not $data{$column}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | unless (@error_list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Check the unique constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | @error_list = check_uniques($self, \%data, $check_columns); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | $self->set_columns(\%data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | if (@error_list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | return { 'errors' => \@error_list }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | return {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # Returns whether any of the primary columns have changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # @TODO Write tests for this function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub primary_cols_have_changed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
primary_cols_have_changed: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | foreach ( $self->result_source->primary_columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | return 1 if $self->is_column_changed($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | sub check_uniques { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_uniques: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my $check_columns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | my %unique_constraints = $source->unique_constraints(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | my %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | foreach my $constraint ( sort keys %unique_constraints ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Skip the primary constraint uniqueness test if self is in_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # and the primary columns haven't changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 24 | ▶ | next if $constraint eq 'primary' and $self->in_storage and not primary_cols_have_changed($self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$constraint eq "primary" and $self->in_storage and not primary_cols_have_changed($self)
$constraint eq "primary" and $self->in_storage
MC/DC66%2/3
$constraint eq "primary" and $self->in_storage and not primary_cols_have_changed($self)
$constraint eq "primary"
$self->in_storage
not primary_cols_have_changed($self)
Truth table75%3/4
A and B and not(C)
A= $constraint eq "primary"B= $self->in_storageC= not primary_cols_have_changed($self)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | my $search = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 41 | ▶ | next unless ( not keys %$check_columns ) or $check_columns->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not keys %$check_columns or $check_columns->{$_}
MC/DC0%0/2
not keys %$check_columns or $check_columns->{$_}
not keys %$check_columns
$check_columns->{$_}
Truth table33%1/3
not(A) or B
A= not keys %$check_columnsB= $check_columns->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 23 | ($_ => $data->{$_}) } @{ $unique_constraints{$constraint} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Exclude this entries primary keys to the search for dupes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # to not detect itself when updating. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 23 | ▶ | unless ( $constraint eq 'primary' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 18 | for my $column ( $source->primary_columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | $search->{$column} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 18 | '!=' => $data->{$column}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # If there is an entry with the combined value defined above... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 23 | ▶ | if ( $source->resultset->count($search) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | foreach my $key ( @{ $unique_constraints{$constraint} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | ▶ | $errors{$key} = [] unless defined $errors{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | my @other_fields = @{ $unique_constraints{$constraint} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Remove the field so we get a list of other fields in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # combination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | ▶ | $index++ until $other_fields[$index] eq $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 10 | splice(@other_fields, $index, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # If there are no keys other than the key that isnt unique, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # then write the error as singular else explain the combination. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 10 | ▶ | if ( $#other_fields >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | push @{$errors{$key}}, { $key => 'must be unique when combined with '.join(', ',@other_fields) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | push @{$errors{$key}}, { $key => 'must be unique' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | ▶ | if ( %errors ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Convert hash into the array of hashrefs like the validate returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | return map { { $_ => join( ' and ', map { values %$_ } @{ $errors{$_} } ) } } keys %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | sub insert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | my $result = $self->validate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # If errors return the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | ▶ | if ($result->{errors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # Else do the normal insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | my $columns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | $self->set_inflated_columns($columns) if $columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | my $result = $self->validate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | # If errors return the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | if ($result->{errors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Else do the normal update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # =============== Validatators =============== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | ▶ | sub _val_email { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_email: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 11 | my ($mand, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 11 | ▶ | if (not defined $value) { $value = ''; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 11 | ▶ | if ( !Email::Valid->address($value) && $mand ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
not "Email::Valid"->address($value) and $mand
MC/DC100%2/2
not "Email::Valid"->address($value) and $mand
not "Email::Valid"->address($value)
$mand
Truth table100%3/3
not(A) and B
A= not "Email::Valid"->address($value)B= $mand
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | return ( undef, { msg => 'address is blank or not valid' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ▶ | } elsif ( !Email::Valid->address($value) && $value ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not "Email::Valid"->address($value) and $value
MC/DC100%2/2
not "Email::Valid"->address($value) and $value
not "Email::Valid"->address($value)
$value
Truth table100%3/3
not(A) and B
A= not "Email::Valid"->address($value)B= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | return ( undef, { msg => 'address is blank or not valid' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 9 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 31 | ▶ | sub _val_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_text: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 31 | my ($mand, $len, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 31 | ▶ | if ($mand && ( not( defined $value ) or $value eq '' )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
$mand and !defined($value) || $value eq ""
not defined $value or $value eq ""
MC/DC66%2/3
$mand and !defined($value) || $value eq ""
$mand
not defined $value
$value eq ""
Truth table75%3/4
A and not(B) or C
A= $mandB= not defined $valueC= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ▶ | } elsif ($len && length($value) && (length($value) > $len) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$len and length $value and length $value > $len
$len and length $value
MC/DC66%2/3
$len and length $value and length $value > $len
$len
length $value
length $value > $len
Truth table75%3/4
A and B and C
A= $lenB= length $valueC= length $value > $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ▶ | } elsif (defined $value && $value !~ /^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>\/\@\w]*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $value and not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
MC/DC100%2/2
defined $value and not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
defined $value
not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
Truth table100%3/3
A and not(B)
A= defined $valueB= not $value =~ m{^([\d \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\?\;\n\r\<\>/\@\w]*)$}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | return (undef, { msg => 'can only use letters, 0-9 and -.,\'\"!&#$?:()[]=%<>;/@ (do not cut and paste from a Word document, you must Save As text only)' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # This is to ensure that $1 is from the last regex match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 28 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 19 | return ($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | # _val_password is the same as _val_text but it also allows {}s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | sub _val_password { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_password: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 7 | my ($mand, $len, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 7 | ▶ | if ($mand && (!$value || $value =~ /bogus="1"/)) { #tiny mce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition50%3/6
$mand and !$value || $value =~ /bogus="1"/
not $value or $value =~ /bogus="1"/
MC/DC33%1/3
$mand and !$value || $value =~ /bogus="1"/
$mand
not $value
$value =~ /bogus="1"/
Truth table50%2/4
A and not(B) or C
A= $mandB= not $valueC= $value =~ /bogus="1"/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | ▶ | } elsif ($len && length($value) && (length($value) > $len) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$len and length $value and length $value > $len
$len and length $value
MC/DC66%2/3
$len and length $value and length $value > $len
$len
length $value
length $value > $len
Truth table75%3/4
A and B and C
A= $lenB= length $valueC= length $value > $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | ▶ | } elsif ($value && $value !~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$value and not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
MC/DC100%2/2
$value and not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
$value
not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\[\]\{\}\?\;\n\r\<\>\/\@\w]*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | return (undef, { msg => 'can only use letters, 0-9 and -.,\'\"!&#$?:()[]=%<>;/@ (do not cut and paste from a Word document, you must Save As text only)' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | my $tf = new HTML::TagFilter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # This is to ensure that $1 is from the last regex match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | return ($tf->filter($1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 2 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 10 | ▶ | sub _val_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_int: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 10 | my ($mand, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 10 | ▶ | if ( (not( defined $value ) or $value ne '0') && !$value && $mand ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%6/9
!defined($value) || $value ne 0 and not $value and $mand
!defined($value) || $value ne 0 and not $value
not defined $value or $value ne 0
MC/DC50%2/4
!defined($value) || $value ne 0 and not $value and $mand
not defined $value
$value ne 0
not $value
$mand
Truth table42%3/7
not(A) or B and not(C) and D
A= not defined $valueB= $value ne 0C= not $valueD= $mand
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | ▶ | } elsif ( ( defined $value and ( $value or $value eq '0' ) ) and $value !~ /^[-]?\d+$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition77%7/9
defined $value and $value || $value eq 0 and not $value =~ /^[-]?\d+$/
defined $value and $value || $value eq 0
$value or $value eq 0
MC/DC50%2/4
defined $value and $value || $value eq 0 and not $value =~ /^[-]?\d+$/
defined $value
$value
$value eq 0
not $value =~ /^[-]?\d+$/
Truth table50%3/6
A and B or C and not(D)
A= defined $valueB= $valueC= $value eq 0D= not $value =~ /^[-]?\d+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | return (undef, { msg => 'can only use numbers' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | return ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | sub _val_selected { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_selected: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my ($value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | if (not defined $value or $value eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | return (undef, { msg => 'must be selected' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | ▶ | sub _val_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_number: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | my ($mand, $len, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | ▶ | if ((!defined $value or $value eq '') && $mand) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
!defined($value) || $value eq "" and $mand
not defined $value or $value eq ""
MC/DC66%2/3
!defined($value) || $value eq "" and $mand
not defined $value
$value eq ""
$mand
Truth table60%3/5
not(A) or B and C
A= not defined $valueB= $value eq ""C= $mand
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | ▶ | } elsif ($len && (length($value) > $len) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$len and length $value > $len
MC/DC50%1/2
$len and length $value > $len
$len
length $value > $len
Truth table66%2/3
A and B
A= $lenB= length $value > $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | ▶ | } elsif ($value && $value !~ /^([-\.]*\d[\d\.-]*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$value and not $value =~ /^([-\.]*\d[\d\.-]*)$/
MC/DC100%2/2
$value and not $value =~ /^([-\.]*\d[\d\.-]*)$/
$value
not $value =~ /^([-\.]*\d[\d\.-]*)$/
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ /^([-\.]*\d[\d\.-]*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | return (undef, { msg => 'can only use numbers and . or -' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # This is to ensure that $1 is from the last regex match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | return ($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||