line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geoffrey::Action::Constraint::Unique; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
29813
|
use utf8; |
|
6
|
|
|
|
|
47
|
|
|
6
|
|
|
|
|
37
|
|
4
|
6
|
|
|
6
|
|
239
|
use 5.016; |
|
6
|
|
|
|
|
21
|
|
5
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
203
|
|
6
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
149
|
|
7
|
6
|
|
|
6
|
|
2518
|
use Ref::Util; |
|
6
|
|
|
|
|
8383
|
|
|
6
|
|
|
|
|
308
|
|
8
|
6
|
|
|
6
|
|
602
|
use Time::HiRes qw/ time /; |
|
6
|
|
|
|
|
1433
|
|
|
6
|
|
|
|
|
32
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$Geoffrey::Action::Constraint::Unique::VERSION = '0.000205'; |
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
786
|
use parent 'Geoffrey::Role::Action'; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
35
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add { |
15
|
11
|
|
|
11
|
1
|
6707
|
my ( $self, $s_table_name, $hr_params ) = @_; |
16
|
11
|
|
|
|
|
45
|
my $unique = $self->converter->unique; |
17
|
11
|
50
|
|
|
|
27
|
if ( !$unique ) { |
18
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::NotSupportedException; |
19
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::NotSupportedException::throw_unique( 'add', $self->converter ); |
20
|
|
|
|
|
|
|
} |
21
|
11
|
100
|
|
|
|
25
|
if ( !$s_table_name ) { |
22
|
2
|
|
|
|
|
563
|
require Geoffrey::Exception::RequiredValue; |
23
|
2
|
|
|
|
|
9
|
Geoffrey::Exception::RequiredValue::throw_table_name( __PACKAGE__ . '::add' ); |
24
|
|
|
|
|
|
|
} |
25
|
9
|
50
|
|
|
|
20
|
return () unless $hr_params; |
26
|
9
|
100
|
|
|
|
26
|
if ( !Ref::Util::is_hashref($hr_params) ) { |
27
|
2
|
|
|
|
|
591
|
require Geoffrey::Exception::General; |
28
|
2
|
|
|
|
|
9
|
Geoffrey::Exception::General::throw_wrong_ref( __PACKAGE__ . '::add', 'hash' ); |
29
|
|
|
|
|
|
|
} |
30
|
7
|
100
|
66
|
|
|
27
|
if ( !$hr_params->{columns} || scalar @{ $hr_params->{columns} } == 0 ) { |
|
5
|
|
|
|
|
31
|
|
31
|
2
|
|
|
|
|
13
|
require Geoffrey::Exception::RequiredValue; |
32
|
2
|
|
|
|
|
10
|
Geoffrey::Exception::RequiredValue::throw_table_column( __PACKAGE__ . '::add' ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
5
|
|
|
|
|
16
|
$s_table_name =~ s/"//g; |
36
|
5
|
|
|
|
|
16
|
my $gentime = time; |
37
|
5
|
|
|
|
|
61
|
$gentime =~ s/\.//g; |
38
|
5
|
|
33
|
|
|
18
|
$hr_params->{name} ||= 'uidx_' . $s_table_name . '_' . $gentime; |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
527
|
require Geoffrey::Utils; |
41
|
|
|
|
|
|
|
return Geoffrey::Utils::replace_spare( $unique->add, |
42
|
5
|
100
|
|
|
|
18
|
[ $hr_params->{name}, join q/,/, @{ $hr_params->{columns} } ] ) |
|
2
|
|
|
|
|
10
|
|
43
|
|
|
|
|
|
|
if $self->for_table; |
44
|
|
|
|
|
|
|
return $self->do( |
45
|
|
|
|
|
|
|
Geoffrey::Utils::replace_spare( |
46
|
|
|
|
|
|
|
$unique->append, |
47
|
3
|
|
|
|
|
12
|
[ $hr_params->{name}, $s_table_name, join q/,/, @{ $hr_params->{columns} } ] |
|
3
|
|
|
|
|
13
|
|
48
|
|
|
|
|
|
|
) |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub alter { |
54
|
1
|
|
|
1
|
1
|
43
|
my ( $self, $s_table_name, $hr_column_params ) = @_; |
55
|
1
|
|
|
|
|
6
|
my $unique = $self->converter->unique; |
56
|
1
|
50
|
|
|
|
6
|
if ( !$unique ) { |
57
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::NotSupportedException; |
58
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::NotSupportedException::throw_unique( 'alter', $self->converter ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
return [ |
61
|
1
|
|
|
|
|
5
|
$self->drop( $s_table_name, $hr_column_params ), |
62
|
|
|
|
|
|
|
$self->append( $s_table_name, $hr_column_params ), |
63
|
|
|
|
|
|
|
]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub drop { |
67
|
2
|
|
|
2
|
1
|
5
|
my ( $self, $s_table_name, $hr_column_params ) = @_; |
68
|
2
|
|
|
|
|
6
|
my $unique = $self->converter->unique; |
69
|
2
|
50
|
|
|
|
6
|
if ( !$unique ) { |
70
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::NotSupportedException; |
71
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::NotSupportedException::throw_unique( 'drop', $self->converter ); |
72
|
|
|
|
|
|
|
} |
73
|
2
|
100
|
|
|
|
9
|
if ( !$s_table_name ) { |
74
|
1
|
|
|
|
|
8
|
require Geoffrey::Exception::RequiredValue; |
75
|
1
|
|
|
|
|
6
|
Geoffrey::Exception::RequiredValue::throw_table_name( __PACKAGE__ . '::drop' ); |
76
|
|
|
|
|
|
|
} |
77
|
1
|
|
|
|
|
7
|
require Geoffrey::Utils; |
78
|
|
|
|
|
|
|
return Geoffrey::Utils::replace_spare( $unique->drop, |
79
|
1
|
|
|
|
|
25
|
[ $s_table_name, $hr_column_params->{name}, ] ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub list_from_schema { |
83
|
4
|
|
|
4
|
1
|
12
|
my ( $self, $schema ) = @_; |
84
|
4
|
|
|
|
|
24
|
my $unique = $self->converter->unique; |
85
|
4
|
50
|
|
|
|
13
|
if ( !$unique ) { |
86
|
0
|
|
|
|
|
0
|
require Geoffrey::Exception::NotSupportedException; |
87
|
0
|
|
|
|
|
0
|
Geoffrey::Exception::NotSupportedException::throw_unique( 'list', $self->converter ); |
88
|
|
|
|
|
|
|
} |
89
|
4
|
|
|
|
|
13
|
return $self->converter->unique_information( $self->do_arrayref( $unique->list($schema) ) ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |