| 1 | package Geoffrey::Action::Constraint::ForeignKey; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | $Geoffrey::Action::Constraint::ForeignKey::VERSION = '0.000206'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use parent 'Geoffrey::Role::Action'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 25 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 25 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 25 | require Ref::Util; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 25 | ▶ | if (!Ref::Util::is_hashref($hr_params)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | require Geoffrey::Exception::General; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::add', 'hash'); | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 24 | ▶ | if (!$self->converter->foreign_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | Geoffrey::Exception::NotSupportedException::throw_foreignkey('add', $self->converter); | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | ▶ | if (!exists $hr_params->{table}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | Geoffrey::Exception::RequiredValue::throw_table_name(); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 22 | ▶ | if ( !exists $hr_params->{column} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
exists $hr_params->{"column"} and exists $hr_params->{"reftable"} and exists $hr_params->{"refcolumn"}
exists $hr_params->{"column"} and exists $hr_params->{"reftable"}
MC/DC33%1/3
exists $hr_params->{"column"} and exists $hr_params->{"reftable"} and exists $hr_params->{"refcolumn"}
exists $hr_params->{"column"}
exists $hr_params->{"reftable"}
exists $hr_params->{"refcolumn"}
Truth table50%2/4
A and B and C
A= exists $hr_params->{"column"}B= exists $hr_params->{"reftable"}C= exists $hr_params->{"refcolumn"}
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | || !exists $hr_params->{reftable} | ||||||||||||||||||||||||||||||||||||||||||
| 29 | || !exists $hr_params->{refcolumn}) | ||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||||||
| 32 | Geoffrey::Exception::RequiredValue::throw_reftable_missing($hr_params->{table}) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | if (!exists $hr_params->{reftable}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | Geoffrey::Exception::RequiredValue::throw_refcolumn_missing($hr_params->{table}) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | if (!exists $hr_params->{refcolumn}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | Geoffrey::Exception::RequiredValue::throw_table_column($hr_params->{table}) | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if (!exists $hr_params->{column}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 19 | $hr_params->{reftable} =~ s/"//g; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 19 | $hr_params->{table} =~ s/"//g; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 19 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||
| 42 | my $s_sql = Geoffrey::Utils::replace_spare( | ||||||||||||||||||||||||||||||||||||||||||
| 43 | $self->converter->foreign_key->add, | ||||||||||||||||||||||||||||||||||||||||||
| 44 | [ | ||||||||||||||||||||||||||||||||||||||||||
| 45 | $hr_params->{column}, | ||||||||||||||||||||||||||||||||||||||||||
| 46 | (exists $hr_params->{schema} ? $hr_params->{schema} . q/./ : q//) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | . $hr_params->{reftable}, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | $hr_params->{refcolumn}, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 19 | ▶ | qq~fkey_$hr_params->{table}~ . q~_~ . time | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | ]); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 19 | ▶ | return $s_sql if $self->for_table; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | return $self->do($s_sql); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | sub alter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | ▶ | if (!exists $hr_params->{name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | Geoffrey::Exception::RequiredValue::throw_index_name(__PACKAGE__ . '::alter'); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | if (!$self->converter->foreign_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | Geoffrey::Exception::NotSupportedException::throw_foreignkey('alter', $self->converter); | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | return [$self->drop($hr_params), $self->add($hr_params),]; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 10 | ▶ | sub drop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 10 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 10 | ▶ | if (!$self->converter->foreign_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | Geoffrey::Exception::NotSupportedException::throw_foreignkey('drop', | |||||||||||||||||||||||||||||||||||||||||
| 74 | $self->converter->foreign_key); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||
| 77 | my $s_sql = Geoffrey::Utils::replace_spare($self->converter->foreign_key->drop, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | [$hr_params->{table}, $hr_params->{name}]); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | return $s_sql if $self->for_table; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | return $self->do($s_sql); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub list_from_schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_from_schema: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my ($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my $converter = $self->converter; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | if (!$self->converter->foreign_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | Geoffrey::Exception::NotSupportedException::throw_foreignkey('list', $self->converter); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | return $converter->foreignkey_information( | |||||||||||||||||||||||||||||||||||||||||
| 91 | $self->do_arrayref($self->converter->foreign_key->list($schema))); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||||||||||||||||