| 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.12'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | sub validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=36 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | my @check_columns = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | 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)}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | my %data = $self->get_columns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 | my $columns = $source->columns_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my ($error, @error_list, $stmt); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | for my $column ( keys %$columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ($data{$column}, $error) = $columns->{$column}{validation_function}( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | info => $columns->{$column}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | value => $data{$column}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | data => \%data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | self => $self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 36 | ▶ | my $val_type = (defined $columns->{$column}{val_override}) ? $columns->{$column}{val_override} : $columns->{$column}{data_type}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 36 | ▶ | if ($val_type eq 'email') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | ($data{$column}, $error) = _val_email( $mand, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ▶ | } 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 24 | ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 24 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } elsif ($val_type eq 'password') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ($data{$column}, $error) = _val_password( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } elsif ($val_type eq 'selected') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ($data{$column}, $error) = _val_text( 0, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ($data{$column}, $error) = _val_int( 0, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ($data{$column}, $error) = _val_selected( $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ▶ | } 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 6 | ($data{$column}, $error) = _val_int( $mand, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } elsif ($val_type eq 'number') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ($data{$column}, $error) = _val_number( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ($data{$column}, $error) = _val_text( $mand, $columns->{$column}{size}, $data{$column} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $error-> { msg } ) { push @error_list, { $column => $error->{ msg } }; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # If the column is auto_increment and there is no value set, set it to undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # @TODO decide if this should be deleted all together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | ▶ | unless (@error_list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Check the unique constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | @error_list = check_uniques($self, \%data, $check_columns); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | $self->set_columns(\%data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | if (@error_list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | return { 'errors' => \@error_list }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | return {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # Returns whether any of the primary columns have changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # @TODO Write tests for this function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub primary_cols_have_changed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
primary_cols_have_changed: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | foreach ( $self->result_source->primary_columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | ▶ | return 1 if $self->is_column_changed($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | sub check_uniques { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_uniques: called CC=15 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | my $check_columns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | my $source = $self->result_source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | my %unique_constraints = $source->unique_constraints(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | my %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | foreach my $constraint ( sort keys %unique_constraints ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Skip the primary constraint uniqueness test if self is in_storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # and the primary columns haven't changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | my $search = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 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->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 23 | ($_ => $data->{$_}) } @{ $unique_constraints{$constraint} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Exclude this entries primary keys to the search for dupes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # to not detect itself when updating. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 23 | ▶ | unless ( $constraint eq 'primary' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 18 | for my $column ( $source->primary_columns ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | $search->{$column} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 18 | '!=' => $data->{$column}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # If there is an entry with the combined value defined above... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 23 | ▶ | if ( $source->resultset->count($search) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | foreach my $key ( @{ $unique_constraints{$constraint} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 10 | ▶ | $errors{$key} = [] unless defined $errors{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 10 | my @other_fields = @{ $unique_constraints{$constraint} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # Remove the field so we get a list of other fields in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # combination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | ▶ | $index++ until $other_fields[$index] eq $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | splice(@other_fields, $index, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # If there are no keys other than the key that isnt unique, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # then write the error as singular else explain the combination. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 10 | ▶ | if ( $#other_fields >= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 8 | push @{$errors{$key}}, { $key => 'must be unique when combined with '.join(', ',@other_fields) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | push @{$errors{$key}}, { $key => 'must be unique' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | if ( %errors ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Convert hash into the array of hashrefs like the validate returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 4 | return map { { $_ => join( ' and ', map { values %$_ } @{ $errors{$_} } ) } } keys %errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | sub insert { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insert: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | my $result = $self->validate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # If errors return the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | ▶ | if ($result->{errors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Else do the normal insert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | sub update { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | my $columns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | ▶ | $self->set_inflated_columns($columns) if $columns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my $result = $self->validate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # If errors return the result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | if ($result->{errors}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | # Else do the normal update | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # =============== Validatators =============== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | sub _val_email { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 11 | ▶ | my ($mand, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_email: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | ▶ | if (not defined $value) { $value = ''; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | return ( undef, { msg => 'address is blank or not valid' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ▶ | } 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | return ( undef, { msg => 'address is blank or not valid' } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 9 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub _val_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 30 | ▶ | my ($mand, $len, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_text: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # To ensure the text is correctly encoded etc. SZ 7/12/12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | #my $decoder = Encode::Guess->guess($value); # First guess the decoder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #if (ref($decoder)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # $value = $decoder->decode($value); # If a decoder is found, then decode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | #$value = Encode::encode_utf8($value); # If there is no decoder, assume its UTF8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 30 | ▶ | if ($mand && (!$value || $value =~ /bogus="1"/)) { #tiny mce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition83%5/6
$mand and !$value || $value =~ /bogus="1"/
not $value or $value =~ /bogus="1"/
MC/DC66%2/3
$mand and !$value || $value =~ /bogus="1"/
$mand
not $value
$value =~ /bogus="1"/
Truth table75%3/4
A and not(B) or C
A= $mandB= not $valueC= $value =~ /bogus="1"/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ▶ | } 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ▶ | } elsif ($value && $value !~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\?\;\n\r\<\>\/\@äÄöÖüÜßéÉáÁíÍ]*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$value and not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
MC/DC100%2/2
$value and not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
$value
not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 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)' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 27 | my $tf = new HTML::TagFilter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 27 | ▶ | if ($value) { # This is to prevent empty strings from returning as the last regex match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 17 | return ($tf->filter($1)); # $1 is a tricky value. If value is blank $1 will be the last regex match. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 10 | return ''; # Take that $1. Conditional statement to the face. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # _val_password is the same as _val_text but it also allows {}s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | sub _val_password { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | my ($mand, $len, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_password: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # To ensure the text is correctly encoded etc. SZ 7/12/12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | #my $decoder = Encode::Guess->guess($value); # First guess the decoder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | #if (ref($decoder)){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # $value = $decoder->decode($value); # If a decoder is found, then decode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | #$value = Encode::encode_utf8($value); # If there is no decoder, assume its UTF8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 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"/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | ▶ | } 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 1 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ▶ | } elsif ($value && $value !~ /^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\{\}\?\;\n\r\<\>\/\@äÄöÖüÜßéÉáÁíÍ]*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$value and not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\{\}\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
MC/DC100%2/2
$value and not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\{\}\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
$value
not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\{\}\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
Truth table100%3/3
A and not(B)
A= $valueB= not $value =~ m[^([\w \.\,\-\'\"\!\$\#\%\=\&\:\+\(\)\{\}\?\;\n\r\<\>/\@\303\244\303\204\303\266\303\226\303\274\303\234\303\237\303\251\303\211\303\241\303\201\303\255\303\215]*)$]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 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)' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | my $tf = new HTML::TagFilter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | ▶ | if ($value) { # This is to prevent empty strings from returning as the folder name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | return ($tf->filter($1)); # $1 is a tricky value. If value is blank $1 will be the name of the folder from the instance script. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | return ''; # Take that $1. Conditional statement to the face. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub _val_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 10 | ▶ | my ($mand, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_int: called CC=9 SCAR=22.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | ▶ | } 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+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return (undef, { msg => 'can only use numbers' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | return ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | sub _val_selected { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | ▶ | my ($value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_selected: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | return (undef, { msg => 'must be selected' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | sub _val_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 6 | ▶ | my ($mand, $len, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_val_number: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | return (undef, { msg => 'cannot be blank' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ▶ | } 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | return (undef, { msg => 'is limited to '.$len.' characters' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | ▶ | } 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\.-]*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 1 | return (undef, { msg => 'can only use numbers and . or -' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | ▶ | if ($value ne '') { # This is to prevent empty strings from returning as the folder name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | return ($1); # $1 is a tricky value. If value is blank $1 will be the name of the folder from the instance script. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | return ''; # Take that $1. Conditional statement to the face. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | DBIx::Class::Validation::Structure - DBIx::Class Validation based on the column meta data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | package MyApp::Schema::Result::Artist; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | use base qw/DBIx::Class::Core/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | __PACKAGE__->load_components(qw/Validation::Structure/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | __PACKAGE__->table('artist'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | __PACKAGE__->add_columns(qw/ artistid name /); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | __PACKAGE__->set_primary_key('artistid'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | __PACKAGE__->has_many(cds => 'MyApp::Schema::Result::CD'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | DBIx::Class::Validation::Structure is DBIx::Class Validation based on the column meta data set in add_columns or add_column. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Sean Zellmer E<lt>sean@lejeunerenard.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | Copyright 2013- Sean Zellmer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =over 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | =item L<DBIx::Class> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | =item L<DBIx::Class::Validation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =item L<Email::Valid> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | =item L<HTML::TagFilter> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||