File Coverage

blib/lib/MySQL/Util/Lite/PrimaryKey.pm
Criterion Covered Total %
statement 21 42 50.0
branch 0 10 0.0
condition n/a
subroutine 9 12 75.0
pod n/a
total 30 64 46.8


line stmt bran cond sub pod time code
1             package MySQL::Util::Lite::PrimaryKey;
2              
3             our $VERSION = '0.01';
4              
5 1     1   8 use Modern::Perl;
  1         3  
  1         15  
6 1     1   154 use Moose;
  1         2  
  1         12  
7 1     1   7070 use namespace::autoclean;
  1         2  
  1         8  
8 1     1   70 use Method::Signatures;
  1         2  
  1         11  
9 1     1   415 use Data::Printer alias => 'pdump';
  1         2  
  1         11  
10 1     1   1882 use MySQL::Util::Lite::Column;
  1         3  
  1         107  
11              
12             with 'MySQL::Util::Lite::Roles::NewColumn';
13              
14             has name => (
15             is => 'ro',
16             isa => 'Str',
17             required => 1,
18             );
19              
20             has table_name => (
21             is => 'ro',
22             isa => 'Str',
23             required => 1,
24             );
25              
26             has columns => (
27             is => 'rw',
28             isa => 'ArrayRef[MySQL::Util::Lite::Column]',
29             lazy => 1,
30             builder => '_build_columns',
31             );
32              
33             has _util => (
34             is => 'ro',
35             isa => 'MySQL::Util',
36             required => 1,
37             );
38              
39 1 0   1   726 method get_columns {
  0     0      
  0            
40              
41 0           return @{ $self->columns };
  0            
42             }
43              
44             =head2 is_autoinc
45              
46             Checks if the primary key is a single column and it has autoinc.
47              
48             Returns: Bool
49            
50             =cut
51              
52 1 0   1   750 method is_autoinc {
  0     0      
  0            
53              
54 0           my @cols = $self->get_columns();
55 0 0         if ( @cols == 1 ) {
56 0           my $col = shift @cols;
57 0 0         if ( $col->is_autoinc ) {
58 0           return 1;
59             }
60             }
61              
62 0           return 0;
63             }
64              
65 1 0   1   937 method _build_columns {
  0     0      
  0            
66              
67 0           my $aref = $self->_util->get_constraint(
68             table => $self->table_name,
69             name => $self->name
70             );
71              
72 0           my @cols;
73 0           foreach my $col (@$aref) {
74             my $href = $self->_util->describe_column(
75             table => $col->{TABLE_NAME},
76             column => $col->{COLUMN_NAME}
77 0           );
78 0           my $new = $self->new_column($href);
79 0           push @cols, $new;
80             }
81              
82 0           return \@cols;
83             }
84              
85             1;