lib/MySQL/Util/Lite/PrimaryKey.pm

filter: Statementstmt 59.6% 31 / 52 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod n/a totaltotal 54.0% 40 / 74 CC 7 SCAR 17.3
CC
7
Cov
50%
is_autoinc
14.7
_build_columns
8.5
get_columns
3.7
CRAP 5.6
« lib/MySQL/Util/Lite/Schema.pm ↑ Summary script/myutil_dump_tables.pl »
1 package MySQL::Util::Lite::PrimaryKey;
2  
3 1 our $VERSION = '0.01';
4  
5 1 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Printer alias => 'pdump';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MySQL::Util::Lite::Column;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 with 'MySQL::Util::Lite::Roles::NewColumn';
13  
14 1 has name => (
15 is => 'ro',
16 isa => 'Str',
17 required => 1,
18 );
19  
20 1 has table_name => (
21 is => 'ro',
22 isa => 'Str',
23 required => 1,
24 );
25  
26 1 has columns => (
27 is => 'rw',
28 isa => 'ArrayRef[MySQL::Util::Lite::Column]',
29 lazy => 1,
30 builder => '_build_columns',
31 );
32  
33 1 has _util => (
34 is => 'ro',
35 isa => 'MySQL::Util',
36 required => 1,
37 );
38  
39 0 ▶method get_columns {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine get_columns: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
40  
41 0 return @{ $self->columns };
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 0 ▶method is_autoinc {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine is_autoinc: not called CC=4 SCAR=26.9
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
53  
54 0 my @cols = $self->get_columns();
55 0 ▶ if ( @cols == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cols == 1) 0 0 0
56 0 my $col = shift @cols;
57 0 ▶ if ( $col->is_autoinc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col->is_autoinc) 0 0 0
58 0 return 1;
59 }
60 }
61  
62 0 return 0;
63 }
64  
65 0 ▶method _build_columns {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine _build_columns: not called CC=3 SCAR=21.3
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 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 1;
« lib/MySQL/Util/Lite/Schema.pm ↑ Summary script/myutil_dump_tables.pl »