Geoffrey/Action/Trigger.pm

filter: Statementstmt 92.4% 61 / 66 Branchbran 75.0% 30 / 40 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 79.7% 114 / 143 CC 25 SCAR 19.0
CC
25
Cov
82%
add
11.7
alter
9.3
drop
5.2
CRAP 6.7
« Geoffrey/Action/Constraint/ForeignKey.pm ↑ Summary Geoffrey/Action/Column.pm »
1 package Geoffrey::Action::Trigger;
2  
3 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Geoffrey::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Geoffrey::Exception::RequiredValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Geoffrey::Exception::NotSupportedException;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 $Geoffrey::Action::Trigger::VERSION = '0.000206';
12  
13 5 ▶use parent 'Geoffrey::Role::Action';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 15 ▶sub add {
Subroutine add: called CC=10 SCAR=24.6
Pod documented
16 15 my ($self, $params, $options) = @_;
17 15 my $trigger = $self->converter->trigger;
18  
19 15 ▶ Geoffrey::Exception::NotSupportedException::throw_action() if !$trigger || !$trigger->add;
Branch: 1 branch
BranchTrueFalseTotal
unless $trigger and $trigger->add 0 15 15
Condition33%1/3
$trigger and $trigger->add
!ll&&!rl&&r
0015
MC/DC0%0/2
$trigger and $trigger->add
$trigger $trigger->add
Truth table33%1/3
A and B
A= $triggerB= $trigger->add
ABresult
0X0
100
111
20 15 ▶ Geoffrey::Exception::RequiredValue::throw_trigger_name('for add trigger') if !$params->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"name"} 4 11 15
21 11 ▶ Geoffrey::Exception::RequiredValue::throw_table_name('for add trigger') if !$params->{event_object_table};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"event_object_table"} 2 9 11
22 9 ▶ Geoffrey::Exception::RequiredValue::throw_common('event_manipulation') if !$params->{event_manipulation};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"event_manipulation"} 7 2 9
23 2 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_timing') if !$params->{action_timing};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_timing"} 0 2 2
24 2 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_orientation') if !$params->{action_orientation};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_orientation"} 0 2 2
25 2 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_statement') if !$params->{action_statement};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_statement"} 0 2 2
26  
27 2 my $result = $self->_find_same_trigger($params->{event_object_table}, $params->{name}, $params->{schema});
28  
29 2 ▶ if (@{$result} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$result;} > 0) 0 2 2
30 0 $self->drop($params->{name}, $params->{event_object_table});
31 0 $params->{event_manipulation} .= ' OR ' . $result->[0]->{event_manipulation};
32 }
33  
34 my $sql = Geoffrey::Utils::replace_spare(
35 $trigger->add($options),
36 [
37 $params->{name}, $params->{action_timing}, $params->{event_manipulation},
38 $params->{event_object_table}, $params->{action_orientation}, $params->{action_statement},
39 2 ]);
40 2 return $self->do($sql);
41 }
42  
43 8 ▶sub alter {
Subroutine alter: called CC=9 SCAR=22.3
Pod documented
44 8 my ($self, $params, $options) = @_;
45 8 my $trigger = $self->converter->trigger;
46 8 ▶ Geoffrey::Exception::NotSupportedException::throw_action() if !$trigger || !$trigger->alter;
Branch: 1 branch
BranchTrueFalseTotal
unless $trigger and $trigger->alter 0 6 6
Condition66%2/3
$trigger and $trigger->alter
!ll&&!rl&&r
017
MC/DC0%0/2
$trigger and $trigger->alter
$trigger $trigger->alter
Truth table33%1/3
A and B
A= $triggerB= $trigger->alter
ABresult
0X0
100
111
47 6 ▶ Geoffrey::Exception::RequiredValue::throw_trigger_name('for drop trigger') if !$params->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"name"} 1 5 6
48 5 ▶ Geoffrey::Exception::RequiredValue::throw_table_name('for drop trigger') if !$params->{event_object_table};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"event_object_table"} 1 4 5
49 4 ▶ Geoffrey::Exception::RequiredValue::throw_common('event_manipulation') if !$params->{event_manipulation};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"event_manipulation"} 1 3 4
50 3 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_timing') if !$params->{action_timing};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_timing"} 1 2 3
51 2 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_orientation') if !$params->{action_orientation};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_orientation"} 1 1 2
52 1 ▶ Geoffrey::Exception::RequiredValue::throw_common('action_statement') if !$params->{action_statement};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"action_statement"} 1 0 1
53  
54 0 return [$self->drop($params, $options), $self->add($params, $options),];
55 }
56  
57 5 ▶sub drop {
Subroutine drop: called CC=5 SCAR=16.5
Pod documented
58 5 my ($self, $name, $table) = @_;
59 5 my $trigger = $self->converter->trigger;
60 5 ▶ Geoffrey::Exception::NotSupportedException::throw_action() if !$trigger || !$trigger->drop;
Branch: 1 branch
BranchTrueFalseTotal
unless $trigger and $trigger->drop 0 5 5
Condition33%1/3
$trigger and $trigger->drop
!ll&&!rl&&r
005
MC/DC0%0/2
$trigger and $trigger->drop
$trigger $trigger->drop
Truth table33%1/3
A and B
A= $triggerB= $trigger->drop
ABresult
0X0
100
111
61 5 ▶ Geoffrey::Exception::RequiredValue::throw_trigger_name('for drop trigger') if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 3 5
62 3 ▶ Geoffrey::Exception::RequiredValue::throw_table_name('for drop trigger') if !$table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 2 1 3
63 1 return $self->do(Geoffrey::Utils::replace_spare($trigger->drop, [$name, $table]));
64 }
65  
66 3 ▶sub list {
Subroutine list: called CC=3 SCAR=11.8
Pod documented
67 3 my ($self, $schema) = @_;
68 3 my $trigger = $self->converter->trigger;
69 3 ▶ if (!$trigger || !$trigger->list) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($trigger and $trigger->list) 0 1 1
Condition66%2/3
$trigger and $trigger->list
!ll&&!rl&&r
021
MC/DC0%0/2
$trigger and $trigger->list
$trigger $trigger->list
Truth table33%1/3
A and B
A= $triggerB= $trigger->list
ABresult
0X0
100
111
70 0 Geoffrey::Exception::NotSupportedException::throw_action();
71 }
72 1 return $trigger->information($self->do_arrayref($trigger->list($schema)));
73 }
74  
75 2 ▶sub _find_same_trigger {
Subroutine _find_same_trigger: called CC=2 SCAR=7.6
76 2 my ($self, $table, $name, $schema) = @_;
77 2 my $trigger = $self->converter->trigger;
78 2 ▶ return [] if !$trigger->can('find_by_name_and_table');
Branch: 1 branch
BranchTrueFalseTotal
unless $trigger->can("find_by_name_and_table") 2 0 2
79 0 return $self->do_arrayref($trigger->find_by_name_and_table, [$table, $name, $schema]);
80 }
81  
82 5 1;
83  
84 __END__
« Geoffrey/Action/Constraint/ForeignKey.pm ↑ Summary Geoffrey/Action/Column.pm »