| 1 | package Alzabo::Create::ForeignKey; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Alzabo::Create; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Alzabo::Exceptions ( abbr => 'params_exception' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Alzabo::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Params::Validate qw( :all ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | Params::Validate::validation_options | ||||||||||||||||||||||||||||
| 12 | 0 | ▶ | ( on_fail => sub { params_exception join '', @_ } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use base qw(Alzabo::ForeignKey); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 9 | $VERSION = 2.0; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | 1; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub new | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | validate( @_, { columns_from => { type => ARRAYREF | OBJECT }, | |||||||||||||||||||||||||||
| 26 | columns_to => { type => ARRAYREF | OBJECT }, | ||||||||||||||||||||||||||||
| 27 | cardinality => { type => ARRAYREF }, | ||||||||||||||||||||||||||||
| 28 | from_is_dependent => { type => SCALAR }, | ||||||||||||||||||||||||||||
| 29 | to_is_dependent => { type => SCALAR }, | ||||||||||||||||||||||||||||
| 30 | comment => { type => UNDEF | SCALAR, | ||||||||||||||||||||||||||||
| 31 | default => '' }, | ||||||||||||||||||||||||||||
| 32 | } ); | ||||||||||||||||||||||||||||
| 33 | 0 | my %p = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | $self->set_columns_from( $p{columns_from} ); | |||||||||||||||||||||||||||
| 38 | 0 | $self->set_columns_to( $p{columns_to} ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | $self->set_cardinality( @{ $p{cardinality} } ); | |||||||||||||||||||||||||||
| 41 | 0 | $self->set_from_is_dependent( $p{from_is_dependent} ); | |||||||||||||||||||||||||||
| 42 | 0 | $self->set_to_is_dependent( $p{to_is_dependent} ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | $self->set_comment( $p{comment} ); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | return $self; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub set_columns_from | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_columns_from: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $c = Alzabo::Utils::is_arrayref( $_[0] ) ? shift : [ shift ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | validate_pos( @$c, ( { isa => 'Alzabo::Create::Column' } ) x @$c ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( exists $self->{columns_to} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | params_exception | ||||||||||||||||||||||||||||
| 59 | "The number of columns in each part of the relationship must be the same" | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | unless @{ $self->{columns_to} } == @$c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | $self->{columns_from} = $c; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | sub set_columns_to | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_columns_to: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | my $c = Alzabo::Utils::is_arrayref( $_[0] ) ? shift : [ shift ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | validate_pos( @$c, ( { isa => 'Alzabo::Create::Column' } ) x @$c ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ( exists $self->{columns_from} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | params_exception | ||||||||||||||||||||||||||||
| 76 | "The number of columns in each part of the relationship must be the same" | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless @{ $self->{columns_from} } == @$c; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | $self->{columns_to} = $c; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | sub set_cardinality | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_cardinality: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my @card = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | params_exception "Incorrect number of elements for cardinality" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | unless scalar @card == 2; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | foreach my $c ( @card ) | |||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | params_exception "Invalid cardinality piece: $c" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | unless $c =~ /^[1n]$/i; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | params_exception "Invalid cardinality: $card[0]..$card[1]" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$card[0] eq "n" and $card[1] eq "n"
MC/DC0%0/2
$card[0] eq "n" and $card[1] eq "n"
$card[0] eq "n"
$card[1] eq "n"
Truth table0%0/3
A and B
A= $card[0] eq "n"B= $card[1] eq "n"
| |||||||||||||||||||||||||||||
| 99 | if $card[0] eq 'n' && $card[1] eq 'n'; | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | $self->{cardinality} = \@card; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub set_from_is_dependent | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_from_is_dependent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | $self->{from_is_dependent} = shift; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub set_to_is_dependent | ||||||||||||||||||||||||||||
| 112 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
set_to_is_dependent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | $self->{to_is_dependent} = shift; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub set_comment { $_[0]->{comment} = defined $_[1] ? $_[1] : '' } | ||||||||||||||||||||||||||
|
Subroutine
set_comment: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||