lib/Data/HandyGen/mysql/ColumnDef.pm

filter: Statementstmt 33.3% 12 / 36 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 3 / 7 Podpod 100% 3 / 3 totaltotal 26.4% 18 / 68 CC 10 SCAR 33.3
CC
10
Cov
22%
new
56.0
AUTOLOAD
12.0
is_auto_increment
6.0
CRAP 27.8
« lib/Data/HandyGen/mysql.pm ↑ Summary script/hd_delete_all.pl »
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
BranchTrueFalseTotal
if (@defs == 1 and ref $defs[0] eq 'HASH') { } 0 0 0
elsif (@defs % 2 == 0) { } 0 0 0
Condition0%0/3
@defs == 1 and ref $defs[0] eq "HASH"
!ll&&!rl&&r
000
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (uc $key ne $key) 0 0 0
73 0 $params{uc $key} = delete $params{$key};
74 }
75 }
76  
77 0 ▶ my $class = ref $inv || $inv;
Condition0%0/3
ref $inv || $inv
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $inv || $inv
ref $inv $inv
Truth table0%0/3
A || B
A= ref $invB= $inv
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$self->{'EXTRA'} =~ /auto_increment/ ? : 0 0 0
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
BranchTrueFalseTotal
if $key eq "DESTROY" 0 0 0
124  
125 0 ▶ if ( exists($self->{$key}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$key}) { } 0 0 0
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__
« lib/Data/HandyGen/mysql.pm ↑ Summary script/hd_delete_all.pl »