| 1 | package Data::HandyGen::mysql::ColumnDef; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.0.5'; | |||||||||||||||||||||||||||||||
| 7 | 2 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | Data::HandyGen::mysql::ColumnDef - Manages one column definition | ||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | This documentation refers to Data::HandyGen::mysql::ColumnDef version 0.0.5 | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | use Data::HandyGen::mysql::ColumnDef; | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | my $cd = Data::HandyGen::mysql::ColumnDef->new('colname', %column_definition); | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | # true if 'colname' is auto_increment | ||||||||||||||||||||||||||||||||
| 29 | my $res = $cd->is_auto_increment(); | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | # get column type | ||||||||||||||||||||||||||||||||
| 32 | my $type = $cd->data_type(); | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | =head1 CAUTION | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | This module is not intended for use outside Data::HandyGen. Its interface may be changed in the future. | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | This class is a container of column definition retrieved from information_schema.columns. | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | =head2 new($colname, %params) | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | Constructor. | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | %params is a hash which contains a column definition retrieved from information_schema.columns. | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 58 | 0 | my ($inv, $colname, @defs) = @_; | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | my %params = (); | |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (@defs == 1 and ref $defs[0] eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
@defs == 1 and ref $defs[0] eq "HASH"
MC/DC0%0/2
@defs == 1 and ref $defs[0] eq "HASH"
@defs == 1
ref $defs[0] eq "HASH"
Truth table0%0/3
A and B
A= @defs == 1B= ref $defs[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 62 | 0 | %params = %{ $defs[0] }; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | elsif (@defs % 2 == 0) { | ||||||||||||||||||||||||||||||||
| 65 | 0 | %params = @defs; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||
| 68 | 0 | confess "Invalid nums of defs. num = " . scalar(@defs); | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | for my $key (keys %params) { | |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ( uc $key ne $key ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $params{uc $key} = delete $params{$key}; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $class = ref $inv || $inv; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $inv || $inv
MC/DC0%0/2
ref $inv || $inv
ref $inv
$inv
Truth table0%0/3
A || B
A= ref $invB= $inv
| |||||||||||||||||||||||||||||||||
| 78 | 0 | my $self = bless { name => $colname, %params }, $class; | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | =head2 name() | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | Returns column name. | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub name { shift->{name}; } | ||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | =head2 is_auto_increment() | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | Returns 1 if the column is auto_increment. Otherwise returns 0. | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub is_auto_increment { | ||||||||||||||||||||||||||||||
|
Subroutine
is_auto_increment: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 100 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return ( $self->{EXTRA} =~ /auto_increment/ ) ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | =head2 To retrieve other attributes | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | information_schema.columns has many attributes. You can retrieve one of them by using a method which name corresponds to attribute name in lowercase. | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | For example, you can retrieve 'DATA_TYPE' like this: | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | $type = $column_def->data_type(); | ||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 117 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 0 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||
| 120 | 0 | $AUTOLOAD =~ /::(\w+)$/; | |||||||||||||||||||||||||||||||
| 121 | 0 | my $key = uc($1); | |||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return if $key eq 'DESTROY'; # do nothing | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( exists($self->{$key}) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | 0 | return $self->{$key}; | |||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||||||
| 129 | 0 | confess "[$AUTOLOAD] : no such attribute"; | |||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 2 | 1; | |||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | __END__ | ||||||||||||||||||||||||||||||||