| 1 | package Geoffrey::Action::Table; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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::Table::VERSION = '0.000206'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use parent 'Geoffrey::Role::Action'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 8 | ▶ | sub _hr_merge_templates { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hr_merge_templates: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 8 | my ($self, $s_template, $s_table_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | if (($self->{template} && !$self->{template}->template($s_template)) || !$self->{template}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$self->{"template"} and not $self->{"template"}->template($s_template) or not $self->{"template"}
$self->{"template"} and not $self->{"template"}->template($s_template)
MC/DC0%0/3
$self->{"template"} and not $self->{"template"}->template($s_template) or not $self->{"template"}
$self->{"template"}
not $self->{"template"}->template($s_template)
not $self->{"template"}
Truth table40%2/5
A and not(B) or not(C)
A= $self->{"template"}B= not $self->{"template"}->template($s_template)C= not $self->{"template"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | require Geoffrey::Exception::Template; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | Geoffrey::Exception::Template::throw_template_not_found($s_template); | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | my $ar_template_columns = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | my $ar_template_constraints = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | $self->column_action->for_table(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | $self->constraint_action->for_table(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | for (@{$self->{template}->template($s_template)}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 38 | $_->{table} = $s_table_name; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 38 | push @{$ar_template_columns}, | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | $self->column_action->add($_, | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | $self->constraint_action->add($s_table_name, $_, $ar_template_constraints)); | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | $self->column_action->for_table(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | $self->constraint_action->for_table(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | return {columns => $ar_template_columns, constraints => $ar_template_constraints}; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 12 | ▶ | sub postfix { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
postfix: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 12 | ▶ | return $_[0]->{postfix} // q~~ if !defined $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_[0]{"postfix"} // ""
MC/DC100%1/1
$_[0]{"postfix"} // ""
$_[0]{"postfix"}
Truth table100%2/2
A
A= $_[0]{"postfix"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | $_[0]->{postfix} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | return $_[0]->{postfix}; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 12 | ▶ | sub prefix { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefix: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 12 | ▶ | return $_[0]->{prefix} // q~~ if !defined $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_[0]{"prefix"} // ""
MC/DC100%1/1
$_[0]{"prefix"} // ""
$_[0]{"prefix"}
Truth table100%2/2
A
A= $_[0]{"prefix"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | $_[0]->{prefix} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | return $_[0]->{prefix}; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 64 | ▶ | sub constraint_action { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
constraint_action: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 64 | ▶ | return $self->{constraint_action} if ($self->{constraint_action}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | require Geoffrey::Action::Constraint; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | $self->{constraint_action} | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | = Geoffrey::Action::Constraint->new(converter => $self->converter, dbh => $self->dbh,); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | return $self->{constraint_action}; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 64 | ▶ | sub column_action { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column_action: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 64 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 64 | ▶ | return $self->{column_action} if ($self->{column_action}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | require Geoffrey::Action::Column; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | $self->{column_action} | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | = Geoffrey::Action::Column->new(converter => $self->converter, dbh => $self->dbh,); | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | return $self->{column_action}; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | ▶ | sub action { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
action: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | my ($self, $s_action) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | $s_action = join q//, map {ucfirst} split /_/, $s_action; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | return Geoffrey::Utils::action_obj_from_name( | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | $s_action, | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | dbh => $self->dbh, | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | converter => $self->converter, | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | dryrun => $self->dryrun | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 13 | ▶ | if (!$hr_params || !$hr_params->{name}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$hr_params and $hr_params->{"name"}
MC/DC50%1/2
$hr_params and $hr_params->{"name"}
$hr_params
$hr_params->{"name"}
Truth table66%2/3
A and B
A= $hr_paramsB= $hr_params->{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | Geoffrey::Exception::RequiredValue::throw_table_name(__PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | my @columns = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | my $ar_constraints = []; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 12 | my $constraint_action = $self->constraint_action; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | my $column_action = $self->column_action; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 12 | ▶ | if ($hr_params->{template}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | my $templates = $self->_hr_merge_templates($hr_params->{template}, $hr_params->{name}); | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | push @columns, @{$templates->{columns}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | push @{$ar_constraints}, @{$templates->{constraints}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | $constraint_action->for_table(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | $column_action->for_table(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | for my $hr_column (@{$hr_params->{columns}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 39 | ▶ | $hr_column->{schema} = $hr_params->{schema} if exists $hr_params->{schema}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 39 | $hr_column->{table} = $hr_params->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 39 | my $const = $constraint_action->add($hr_params->{name}, $hr_column, $ar_constraints); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 39 | push @columns, $column_action->add($hr_column, $const); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | for (@{$hr_params->{constraints}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $_->{schema} = $hr_params->{schema} if exists $hr_params->{schema}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $constraint_action->add($hr_params->{name}, $_, $ar_constraints); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | push @columns, @{$ar_constraints}; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 11 | ▶ | if (scalar @columns == 0 && !$self->converter->can_create_empty_table) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @columns == 0 and not $self->converter->can_create_empty_table
MC/DC50%1/2
scalar @columns == 0 and not $self->converter->can_create_empty_table
scalar @columns == 0
not $self->converter->can_create_empty_table
Truth table66%2/3
A and not(B)
A= scalar @columns == 0B= not $self->converter->can_create_empty_table
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | require Geoffrey::Exception::NotSupportedException; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | Geoffrey::Exception::NotSupportedException::throw_empty_table($self->converter, | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | $hr_params); | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 10 | $constraint_action->for_table(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 10 | $column_action->for_table(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | #prepare finaly created table to SQL | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 10 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | my $sql = Geoffrey::Utils::replace_spare( $self->converter->table->add, [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ($hr_params->{schema} ? $hr_params->{schema} . q/./ : q//) . $self->prefix . $hr_params->{name} . $self->postfix, | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | join(q/,/, @columns), | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | $hr_params->{engine}, $hr_params->{charset} | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 10 | ▶ | ]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 10 | return $self->do($sql); | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | ▶ | sub alter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alter: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 13 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 13 | require Ref::Util; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | ▶ | if (!Ref::Util::is_hashref($hr_params)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | require Geoffrey::Exception::General; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | Geoffrey::Exception::General::throw_wrong_ref(__PACKAGE__ . '::alter', 'hash'); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | ▶ | if (!$hr_params->{name}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | require Geoffrey::Exception::General; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | Geoffrey::Exception::General::throw_no_table_name('to alter'); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 11 | my @ar_result = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 11 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 11 | for (@{$hr_params->{alter}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 13 | my ($s_sub, $s_action) = Geoffrey::Utils::parse_package_sub($_->{action}); | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | my $obj_action = $self->action($s_action); | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | 12 | ▶ | if (!$s_sub || !$obj_action->can($s_sub)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$s_sub and $obj_action->can($s_sub)
MC/DC50%1/2
$s_sub and $obj_action->can($s_sub)
$s_sub
$obj_action->can($s_sub)
Truth table66%2/3
A and B
A= $s_subB= $obj_action->can($s_sub)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | require Geoffrey::Exception::RequiredValue; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | Geoffrey::Exception::RequiredValue::throw_action_sub($s_action); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 11 | $_->{table} = $hr_params->{name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | push @ar_result, $obj_action->$s_sub($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3 | return \@ar_result; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | sub drop { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
drop: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | my ($self, $hr_params) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | require Ref::Util; | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | my $s_name = Ref::Util::is_hashref($hr_params) ? $hr_params->{name} : undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | if (!$s_name) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | require Geoffrey::Exception::General; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | Geoffrey::Exception::General::throw_no_table_name('to drop'); | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | require Geoffrey::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | return $self->do(Geoffrey::Utils::replace_spare($self->converter->table->drop, [$s_name])); | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | ▶ | sub list_from_schema { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_from_schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | my ($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | return [map { $_->{name} } @{$self->do_arrayref($self->converter->table->list($schema), [])}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||