| 1 | package Geoffrey::Action::Column; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use 5.016; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||
| 8 | 4 | $Geoffrey::Action::Column::VERSION = '0.000206'; | |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use parent 'Geoffrey::Role::Action'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 86 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 13 | 86 | my ($self, $hr_params, $constraint) = @_; | |||||||||||||||||||||||||||||||||||||
| 14 | 86 | require Ref::Util; | |||||||||||||||||||||||||||||||||||||
| 15 | 86 | ▶ | 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 | 85 | ▶ | return $self->appending($hr_params->{table}, $hr_params, $constraint) if $self->for_table; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 20 | 8 | my $tables = $self->converter->table; | |||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | if (!$tables || !$tables->can('add_column')) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tables and $tables->can("add_column")
MC/DC50%1/2
$tables and $tables->can("add_column")
$tables
$tables->can("add_column")
Truth table66%2/3
A and B
A= $tablesB= $tables->can("add_column")
| |||||||||||||||||||||||||||||||||||||||
| 22 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||
| 23 | 1 | Geoffrey::Exception::NotSupportedException::throw_column('add', $self->converter); | |||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | if (defined $hr_params->{primarykey}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 26 | 1 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||
| 27 | Geoffrey::Exception::RequiredValue::throw_column_default($hr_params->{table}, | ||||||||||||||||||||||||||||||||||||||
| 28 | 1 | $hr_params->{name}); | |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||
| 30 | 6 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||
| 31 | my $sql = Geoffrey::Utils::replace_spare( | ||||||||||||||||||||||||||||||||||||||
| 32 | $tables->add_column, | ||||||||||||||||||||||||||||||||||||||
| 33 | [ | ||||||||||||||||||||||||||||||||||||||
| 34 | $hr_params->{table}, | ||||||||||||||||||||||||||||||||||||||
| 35 | ( | ||||||||||||||||||||||||||||||||||||||
| 36 | join q/ /, | ||||||||||||||||||||||||||||||||||||||
| 37 | ( | ||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | $hr_params->{name}, $self->converter()->type($hr_params), | ||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$constraint // ()
$self->defaults($hr_params) // ()
MC/DC0%0/2
$constraint // ()
$constraint
()
MC/DC0%0/2
$self->defaults($hr_params) // ()
$self->defaults($hr_params)
()
Truth table66%2/3
A // B
A= $constraintB= ()
Truth table33%1/3
A // B
A= $self->defaults($hr_params)B= ()
| |||||||||||||||||||||||||||||||||||||||
| 39 | $constraint // (), $self->defaults($hr_params) // ()))]); | ||||||||||||||||||||||||||||||||||||||
| 40 | 5 | return $self->do($sql); | |||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | sub drop { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 45 | 5 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||
| 46 | 5 | require Ref::Util; | |||||||||||||||||||||||||||||||||||||
| 47 | 5 | ▶ | if (!Ref::Util::is_hashref($hr_params)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | 1 | require Geoffrey::Exception::General; | |||||||||||||||||||||||||||||||||||||
| 49 | 1 | Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::drop', 'hash'); | |||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||
| 51 | 4 | my $table = $self->converter->table; | |||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if (!$table || !$table->can('drop_column')) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$table and $table->can("drop_column")
MC/DC50%1/2
$table and $table->can("drop_column")
$table
$table->can("drop_column")
Truth table66%2/3
A and B
A= $tableB= $table->can("drop_column")
| |||||||||||||||||||||||||||||||||||||||
| 53 | 3 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||
| 54 | 3 | Geoffrey::Exception::NotSupportedException::throw_column('drop', $self->converter); | |||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||
| 56 | 1 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||
| 57 | return [ | ||||||||||||||||||||||||||||||||||||||
| 58 | map { | ||||||||||||||||||||||||||||||||||||||
| 59 | $self->do( | ||||||||||||||||||||||||||||||||||||||
| 60 | 1 | Geoffrey::Utils::replace_spare($table->drop_column, [$hr_params->{table}, $_])) | |||||||||||||||||||||||||||||||||||||
| 61 | 1 | } @{$hr_params->{dropcolumn}}]; | |||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub list_from_schema { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
list_from_schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 65 | 3 | my ($self, $schema, $table) = @_; | |||||||||||||||||||||||||||||||||||||
| 66 | 3 | my $converter = $self->converter; | |||||||||||||||||||||||||||||||||||||
| 67 | 3 | return $converter->colums_information( | |||||||||||||||||||||||||||||||||||||
| 68 | $self->do_arrayref($converter->table->s_list_columns($schema), [$table])); | ||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 77 | ▶ | sub appending { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
appending: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 77 | my ($self, $s_table_name, $hr_params, $constraint) = @_; | |||||||||||||||||||||||||||||||||||||
| 73 | 77 | ▶ | my $b_primarykey = (defined $hr_params->{primarykey}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 74 | 77 | ▶ | my $b_has_value = (exists $hr_params->{default} || exists $hr_params->{foreignkey}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $hr_params->{"default"} or exists $hr_params->{"foreignkey"}
MC/DC100%2/2
exists $hr_params->{"default"} or exists $hr_params->{"foreignkey"}
exists $hr_params->{"default"}
exists $hr_params->{"foreignkey"}
Truth table100%3/3
A or B
A= exists $hr_params->{"default"}B= exists $hr_params->{"foreignkey"}
| |||||||||||||||||||||||||||||||||||||||
| 75 | 77 | ▶ | if ($b_primarykey && !$b_has_value) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$b_primarykey and not $b_has_value
MC/DC0%0/2
$b_primarykey and not $b_has_value
$b_primarykey
not $b_has_value
Truth table66%2/3
A and not(B)
A= $b_primarykeyB= not $b_has_value
| |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||
| 77 | 0 | Geoffrey::Exception::RequiredValue::throw_column_default($s_table_name, $hr_params->{name}); | |||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||
| 79 | return join q/ /, | ||||||||||||||||||||||||||||||||||||||
| 80 | ( | ||||||||||||||||||||||||||||||||||||||
| 81 | 77 | $hr_params->{name}, $self->converter()->type($hr_params), | |||||||||||||||||||||||||||||||||||||
| 82 | $constraint, $self->defaults($hr_params), | ||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 86 | ▶ | sub defaults { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
defaults: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 87 | 86 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||||||
| 88 | 86 | ▶ | return () if !defined $params->{default}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 89 | 49 | my $defaults = $self->converter()->defaults; | |||||||||||||||||||||||||||||||||||||
| 90 | 49 | my $default_by_key = $defaults->{$params->{default}}; | |||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | 49 | ▶ | unless ($default_by_key) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | 37 | ▶ | return 'DEFAULT ' . $params->{default} if $params->{default} eq q/''/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 94 | 30 | return 'DEFAULT ' . $self->converter()->convert_defaults($params); | |||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | if ($params->{default} eq 'autoincrement') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | return $self->sequences->add($params) if $defaults->{$params->{default}} eq 'sequence'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 99 | 8 | return $defaults->{$params->{default}}; | |||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | elsif (defined $defaults->{$params->{default}}) { | ||||||||||||||||||||||||||||||||||||||
| 102 | 4 | return 'DEFAULT ' . $defaults->{$params->{default}}; | |||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return (); | |||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 4 | 1; | |||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||||||||||||