lib/MySQL/Util/Lite/Column.pm

filter: Statementstmt 49.0% 27 / 55 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 34.0% 34 / 100 CC 16 SCAR 39.7
CC
16
Cov
31%
get_ddl
94.6
get_moose_type
45.9
BEGIN
1.3
CRAP 53.1
« lib/MySQL/Util/Data/Create.pm ↑ Summary lib/MySQL/Util.pm »
1 package MySQL::Util::Lite::Column;
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  
11 1 has name => (
12 is => 'ro',
13 isa => 'Str',
14 required => 1,
15 );
16  
17 1 has key => (
18 is => 'ro',
19 isa => 'Str|Undef',
20 );
21  
22 1 has default => (
23 is => 'ro',
24 isa => 'Str|Undef',
25 );
26  
27 1 has type => (
28 is => 'ro',
29 isa => 'Str',
30 required => 1,
31 );
32  
33 1 has is_null => (
34 is => 'rw',
35 isa => 'Bool',
36 required => 1,
37 );
38  
39 1 has is_autoinc => (
40 is => 'rw',
41 isa => 'Bool',
42 default => 0,
43 );
44  
45 0 ▶method get_moose_type {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine get_moose_type: not called CC=7 SCAR=38.3
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
46  
47 0 my $str;
48 0 my $type = $self->type;
49
50 0 ▶ if ( $type =~ /varchar/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type =~ /varchar/iu) { } 0 0 0
elsif ($type =~ /timestamp/iu or $type =~ /datetime/iu) { } 0 0 0
elsif ($type =~ /enum/iu) { } 0 0 0
51 0 $str = 'Str|HashRef';
52 }
53 ▶ elsif ( $type =~ /timestamp/i || $type =~ /datetime/i) {
Condition0%0/3
$type =~ /timestamp/iu or $type =~ /datetime/iu
l!l&&r!l&&!r
000
MC/DC0%0/2
$type =~ /timestamp/iu or $type =~ /datetime/iu
$type =~ /timestamp/iu $type =~ /datetime/iu
Truth table0%0/3
A or B
A= $type =~ /timestamp/iuB= $type =~ /datetime/iu
ABresult
1X1
011
000
54 0 $str = 'Str|HashRef';
55 }
56 elsif ( $type =~ /enum/i ) {
57 0 $str = 'Str|HashRef';
58 }
59 else {
60 0 $str = 'Num|HashRef';
61 }
62  
63 0 ▶ if ( $self->is_null ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_null) 0 0 0
64 0 $str .= '|Undef';
65 }
66  
67 0 return $str;
68 }
69  
70 0 ▶method get_ddl {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine get_ddl: not called CC=10 SCAR=45.5
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
71 0 my $sql = "`" . $self->name . "` " . $self->type . ' ';
72
73 0 ▶ if( $self->is_null ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_null) { } 0 0 0
74 0 $sql .= " NULL ";
75 }
76 else{
77 0 $sql .= " NOT NULL ";
78 }
79
80 0 my $default = $self->default;
81 0 ▶ if( defined $default && $self->type =~ /varchar/i ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default and $self->type =~ /varchar/iu) 0 0 0
Condition0%0/3
defined $default and $self->type =~ /varchar/iu
!ll&&!rl&&r
000
MC/DC0%0/2
defined $default and $self->type =~ /varchar/iu
defined $default $self->type =~ /varchar/iu
Truth table0%0/3
A and B
A= defined $defaultB= $self->type =~ /varchar/iu
ABresult
0X0
100
111
82 0 $default = "\"$default\""; # Surround default in quotes
83 }
84
85 0 ▶ if( $self->is_null ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_null) { } 0 0 0
86 0 ▶ if( defined $self->default){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->default) { } 0 0 0
87 0 ▶ $sql .= " DEFAULT $default" if defined $self->default;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->default 0 0 0
88 }
89 else{
90 0 $sql .= " DEFAULT NULL ";
91 }
92 }
93 else{
94 0 ▶ $sql .= "DEFAULT $default" if defined $self->default;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->default 0 0 0
95 }
96 0 ▶ $sql .= "AUTO_INCREMENT " if $self->is_autoinc;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_autoinc 0 0 0
97
98 0 return $sql;
99 }
100  
101 1 1;
« lib/MySQL/Util/Data/Create.pm ↑ Summary lib/MySQL/Util.pm »