| 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
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $str; | |||||||||||||||||||||||||||
| 48 | 0 | my $type = $self->type; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $type =~ /varchar/i ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 51 | 0 | $str = 'Str|HashRef'; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | ▶ | elsif ( $type =~ /timestamp/i || $type =~ /datetime/i) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$type =~ /timestamp/iu or $type =~ /datetime/iu
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | 0 | my $sql = "`" . $self->name . "` " . $self->type . ' '; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if( $self->is_null ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $default and $self->type =~ /varchar/iu
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
| |||||||||||||||||||||||||||||
| 82 | 0 | $default = "\"$default\""; # Surround default in quotes | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( $self->is_null ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if( defined $self->default){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $sql .= " DEFAULT $default" if defined $self->default; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else{ | ||||||||||||||||||||||||||||
| 90 | 0 | $sql .= " DEFAULT NULL "; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | else{ | ||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $sql .= "DEFAULT $default" if defined $self->default; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $sql .= "AUTO_INCREMENT " if $self->is_autoinc; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | return $sql; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||