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   1896 use strict;
  1         3  
  1         45  
3 1     1   6 use warnings;
  1         2  
  1         39  
4              
5 1     1   6 use parent 'MySQL::Partition';
  1         2  
  1         7  
6             use Class::Accessor::Lite (
7 1         11 ro => [qw/catch_all_partition_name/],
8 1     1   78 );
  1         3  
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   3 my $self = shift;
14 1 50       6 die "catch_all_partition_name isn't specified" unless $self->catch_all_partition_name;
15              
16 1         15 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   5 my ($self, @args) = @_;
22 1 50       4 die "catch_all_partition_name isn't specified" unless $self->catch_all_partition_name;
23              
24 1         13 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   30 my ($self, $partition_name, $partition_description) = @_;
30              
31 8         12 my $comment;
32 8 100 66     32 if (ref $partition_description && ref $partition_description eq 'HASH') {
33 1         2 $comment = $partition_description->{comment};
34 1 50       4 $comment =~ s/'//g if defined $comment;
35 1         2 $partition_description = $partition_description->{description};
36 1 50       4 die 'no partition_description is specified' unless $partition_description;
37             }
38              
39 8 100 100     83 if ($partition_description !~ /^[0-9]+$/ && $partition_description ne 'MAXVALUE' && $partition_description !~ /\(/) {
      100        
40 3         8 $partition_description = "'$partition_description'";
41             }
42 8         41 my $part = sprintf 'PARTITION %s VALUES LESS THAN (%s)', $partition_name, $partition_description;
43 8 100       21 $part .= " COMMENT = '$comment'" if $comment;
44 8         58 $part;
45             }
46              
47             1;
48             __END__