Geoffrey/Action/Column.pm

filter: Statementstmt 95.5% 64 / 67 Branchbran 90.0% 27 / 30 Conditioncond 66.6% 12 / 18 MC/DCmcdc 33.3% 4 / 12 Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 85.9% 122 / 142 CC 22 SCAR 17.3
CC
22
Cov
90%
add
8.1
defaults
7.1
appending
6.3
CRAP 5.6
« Geoffrey/Action/Trigger.pm ↑ Summary Geoffrey/Action/Table.pm »
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
BranchTrueFalseTotal
unless (&Ref::Util::is_hashref($hr_params)) 1 85 86
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
BranchTrueFalseTotal
if $self->for_table 77 8 85
20 8 my $tables = $self->converter->table;
21 8 ▶ if (!$tables || !$tables->can('add_column')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tables and $tables->can("add_column")) 1 7 8
Condition66%2/3
$tables and $tables->can("add_column")
!ll&&!rl&&r
017
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (defined $hr_params->{"primarykey"}) 1 6 7
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 // ()
l!l&&r!l&&!r
140
$self->defaults($hr_params) // ()
l!l&&r!l&&!r
050
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= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $self->defaults($hr_params)B= ()
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless (&Ref::Util::is_hashref($hr_params)) 1 4 5
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
BranchTrueFalseTotal
unless ($table and $table->can("drop_column")) 3 1 4
Condition66%2/3
$table and $table->can("drop_column")
!ll&&!rl&&r
031
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
defined $hr_params->{'primarykey'} ? : 10 67 77
74 77 ▶ my $b_has_value = (exists $hr_params->{default} || exists $hr_params->{foreignkey}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $hr_params->{'default'} || exists $hr_params->{'foreignkey'} ? : 62 15 77
Condition100%3/3
exists $hr_params->{"default"} or exists $hr_params->{"foreignkey"}
l!l&&r!l&&!r
461615
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"}
ABresult
1X1
011
000
75 77 ▶ if ($b_primarykey && !$b_has_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b_primarykey and not $b_has_value) 0 77 77
Condition66%2/3
$b_primarykey and not $b_has_value
!ll&&!rl&&r
67100
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless defined $params->{"default"} 37 49 86
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
BranchTrueFalseTotal
unless ($default_by_key) 37 12 49
93 37 ▶ return 'DEFAULT ' . $params->{default} if $params->{default} eq q/''/;
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"default"} eq "''" 7 30 37
94 30 return 'DEFAULT ' . $self->converter()->convert_defaults($params);
95 }
96  
97 12 ▶ if ($params->{default} eq 'autoincrement') {
Branch: 2 branches
BranchTrueFalseTotal
if ($params->{'default'} eq 'autoincrement') { } 8 4 12
elsif (defined $$defaults{$params->{'default'}}) { } 4 0 4
98 8 ▶ return $self->sequences->add($params) if $defaults->{$params->{default}} eq 'sequence';
Branch: 1 branch
BranchTrueFalseTotal
if $$defaults{$params->{"default"}} eq "sequence" 0 8 8
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__
« Geoffrey/Action/Trigger.pm ↑ Summary Geoffrey/Action/Table.pm »