DBIx/Class/CDBICompat/Constraints.pm

filter: Statementstmt 22.5% 7 / 31 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 2 / 7 Podpod 0.0% 0 / 2 totaltotal 14.5% 9 / 62 CC 12 SCAR 33.7
CC
12
Cov
13%
constrain_column
42.0
add_constraint
42.0
__ANON__
6.0
CRAP 29.0
« DBIx/Class/Storage/DBI/Firebird/Common.pm ↑ Summary DBIx/Class/CDBICompat/SQLTransformer.pm »
1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::Constraints;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 0 ▶sub constrain_column {
Subroutine constrain_column: not called CC=6 SCAR=37.4
Pod undocumented
8 0 my $class = shift;
9 0 ▶ my $col = $class->find_column(+shift)
Branch: 1 branch
BranchTrueFalseTotal
my $col = $class->find_column(shift()) or return $class->throw_exception("constraint_column needs a valid column") 0 0 0
10 or return $class->throw_exception("constraint_column needs a valid column");
11 0 ▶ my $how = shift
Branch: 1 branch
BranchTrueFalseTotal
my $how = shift() or return $class->throw_exception("constrain_column needs a constraint") 0 0 0
12 or return $class->throw_exception("constrain_column needs a constraint");
13 0 ▶ if (ref $how eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $how eq 'ARRAY') { } 0 0 0
elsif (ref $how eq 'Regexp') { } 0 0 0
14 0 my %hash = map { $_ => 1 } @$how;
15 0 ▶ $class->add_constraint(list => $col => sub { exists $hash{ +shift } });
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 } elsif (ref $how eq "Regexp") {
17 0 ▶ $class->add_constraint(regexp => $col => sub { shift =~ $how });
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 } else {
19 0 $how =~ m/([^:]+)$/; # match is safe - we throw above on empty $how
20 0 my $try_method = sprintf '_constrain_by_%s', lc $1; # $how->moniker;
21 0 ▶ if (my $dispatch = $class->can($try_method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dispatch = $class->can($try_method)) { } 0 0 0
22 0 $class->$dispatch($col => ($how, @_));
23 } else {
24 0 $class->throw_exception("Don't know how to constrain $col with $how");
25 }
26 }
27 }
28  
29 0 ▶sub add_constraint {
Subroutine add_constraint: not called CC=6 SCAR=37.4
Pod undocumented
30 0 my $class = shift;
31 0 ▶ $class->_invalid_object_method('add_constraint()') if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
32 0 ▶ my $name = shift or return $class->throw_exception("Constraint needs a name");
Branch: 1 branch
BranchTrueFalseTotal
my $name = shift() or return $class->throw_exception("Constraint needs a name") 0 0 0
33 0 ▶ my $column = $class->find_column(+shift)
Branch: 1 branch
BranchTrueFalseTotal
my $column = $class->find_column(shift()) or return $class->throw_exception("Constraint $name needs a valid column") 0 0 0
34 or return $class->throw_exception("Constraint $name needs a valid column");
35 0 ▶ my $code = shift
Branch: 1 branch
BranchTrueFalseTotal
my $code = shift() or return $class->throw_exception("Constraint $name needs a code reference") 0 0 0
36 or return $class->throw_exception("Constraint $name needs a code reference");
37 0 ▶ return $class->throw_exception("Constraint $name '$code' is not a code reference")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $code eq "CODE" 0 0 0
38 unless ref($code) eq "CODE";
39  
40 #$column->is_constrained(1);
41 $class->add_trigger(
42 0 ▶ "before_set_$column" => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
43 0 my ($self, $value, $column_values) = @_;
44 0 ▶ $code->($value, $self, $column, $column_values)
Branch: 1 branch
BranchTrueFalseTotal
&$code($value, $self, $column, $column_values) or return $self->throw_exception("$class $column fails '${name}' constraint with '${value}'") 0 0 0
45 or return $self->throw_exception(
46 "$class $column fails '$name' constraint with '$value'");
47 }
48 0 );
49 }
50  
51 2 1;
« DBIx/Class/Storage/DBI/Firebird/Common.pm ↑ Summary DBIx/Class/CDBICompat/SQLTransformer.pm »