File Coverage

blib/lib/Geoffrey/Action/Constraint/Default.pm
Criterion Covered Total %
statement 31 41 75.6
branch 4 8 50.0
condition 0 3 0.0
subroutine 10 10 100.0
pod 3 3 100.0
total 48 65 73.8


line stmt bran cond sub pod time code
1             package Geoffrey::Action::Constraint::Default;
2              
3 4     4   557 use utf8;
  4         9  
  4         26  
4 4     4   167 use 5.016;
  4         12  
5 4     4   20 use strict;
  4         7  
  4         76  
6 4     4   19 use warnings;
  4         15  
  4         104  
7 4     4   388 use Geoffrey::Utils;
  4         8  
  4         133  
8 4     4   24 use Geoffrey::Exception::NotSupportedException;
  4         9  
  4         116  
9              
10 4     4   19 use parent 'Geoffrey::Role::Action';
  4         9  
  4         36  
11              
12             $Geoffrey::Action::Constraint::Default::VERSION = '0.000203';
13              
14             sub add {
15 3     3 1 44 my ($self, $params) = @_;
16 3 100       15 Geoffrey::Exception::RequiredValue::throw_table_name() if !$params->{table};
17 2         9 my $sequence = $self->converter->sequence;
18 1 50       9 if (!$sequence->can('nextval')) {
19 1         3 Geoffrey::Exception::NotSupportedException::throw_sequence('nextval', $self->converter);
20             }
21              
22 0         0 my $s_table = $params->{table} =~ s/"//gr;
23 0         0 $params->{name} =~ s/"//g;
24 0   0     0 $params->{name} //= qq~seq_$s_table~ . q/_/ . time;
25             my $sql = Geoffrey::Utils::replace_spare($sequence->add,
26 0         0 [$params->{name}, 1, 1, $Geoffrey::Utils::INT_64BIT_SIGNED, 1, 1]);
27 0         0 $self->do($sql);
28 0         0 return Geoffrey::Utils::replace_spare($sequence->nextval, [$params->{name}]);
29             }
30              
31             sub drop {
32 3     3 1 2724 my ($self, $name) = @_;
33 3         11 my $sequence = $self->converter->sequence;
34 1 50       7 if (!$sequence->can('drop')) {
35 0         0 Geoffrey::Exception::NotSupportedException::throw_sequence('drop', $self->converter);
36             }
37 1         4 return $self->do(Geoffrey::Utils::replace_spare($sequence->drop, [$name]));
38             }
39              
40             sub list_from_schema {
41 3     3 1 1490 my ($self, $schema) = @_;
42 3         17 my $sequence = $self->converter->sequence;
43 0 0         if (!$sequence->can('list')) {
44 0           Geoffrey::Exception::NotSupportedException::throw_sequence('list', $self->converter);
45             }
46 0           return $self->converter->sequence_information($self->do_arrayref($sequence->list($schema), []));
47             }
48              
49             1;
50              
51             __END__