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   701 use utf8;
  4         10  
  4         23  
4 4     4   163 use 5.016;
  4         12  
5 4     4   22 use strict;
  4         10  
  4         89  
6 4     4   18 use warnings;
  4         8  
  4         115  
7 4     4   458 use Geoffrey::Utils;
  4         10  
  4         127  
8 4     4   25 use Geoffrey::Exception::NotSupportedException;
  4         8  
  4         122  
9              
10 4     4   22 use parent 'Geoffrey::Role::Action';
  4         9  
  4         30  
11              
12             $Geoffrey::Action::Constraint::Default::VERSION = '0.000205';
13              
14             sub add {
15 3     3 1 56 my ($self, $params) = @_;
16 3 100       11 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 3383 my ($self, $name) = @_;
33 3         12 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         5 return $self->do(Geoffrey::Utils::replace_spare($sequence->drop, [$name]));
38             }
39              
40             sub list_from_schema {
41 3     3 1 1878 my ($self, $schema) = @_;
42 3         18 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__