File Coverage

blib/lib/MySQL/Partition/Type/Range.pm
Criterion Covered Total %
statement 30 30 100.0
branch 10 14 71.4
condition 8 9 88.8
subroutine 7 7 100.0
pod n/a
total 55 60 91.6


line stmt bran cond sub pod time code
1             package MySQL::Partition::Type::Range;
2 1     1   396 use strict;
  1         1  
  1         22  
3 1     1   4 use warnings;
  1         2  
  1         21  
4              
5 1     1   3 use parent 'MySQL::Partition';
  1         2  
  1         3  
6             use Class::Accessor::Lite (
7 1         7 ro => [qw/catch_all_partition_name/],
8 1     1   44 );
  1         1  
9              
10             __PACKAGE__->_grow_methods(qw/add_catch_all_partition reorganize_catch_all_partition/);
11              
12             sub _build_add_catch_all_partition_sql {
13 1     1   2 my $self = shift;
14 1 50       2 die "catch_all_partition_name isn't specified" unless $self->catch_all_partition_name;
15              
16 1         7 sprintf 'ALTER TABLE %s ADD PARTITION (%s)',
17             $self->table, $self->_build_partition_part($self->catch_all_partition_name, 'MAXVALUE');
18             }
19              
20             sub _build_reorganize_catch_all_partition_sql {
21 1     1   2 my ($self, @args) = @_;
22 1 50       3 die "catch_all_partition_name isn't specified" unless $self->catch_all_partition_name;
23              
24 1         8 sprintf 'ALTER TABLE %s REORGANIZE PARTITION %s INTO (%s, PARTITION %s VALUES LESS THAN (MAXVALUE))',
25             $self->table, $self->catch_all_partition_name, $self->_build_partition_parts(@args), $self->catch_all_partition_name;
26             }
27              
28             sub _build_partition_part {
29 8     8   22 my ($self, $partition_name, $partition_description) = @_;
30              
31 8         9 my $comment;
32 8 100 66     19 if (ref $partition_description && ref $partition_description eq 'HASH') {
33 1         1 $comment = $partition_description->{comment};
34 1 50       4 $comment =~ s/'//g if defined $comment;
35 1         1 $partition_description = $partition_description->{description};
36 1 50       3 die 'no partition_description is specified' unless $partition_description;
37             }
38              
39 8 100 100     41 if ($partition_description !~ /^[0-9]+$/ && $partition_description ne 'MAXVALUE' && $partition_description !~ /\(/) {
      100        
40 3         6 $partition_description = "'$partition_description'";
41             }
42 8         23 my $part = sprintf 'PARTITION %s VALUES LESS THAN (%s)', $partition_name, $partition_description;
43 8 100       13 $part .= " COMMENT = '$comment'" if $comment;
44 8         32 $part;
45             }
46              
47             1;
48             __END__