line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::HandyGen::mysql::ColumnDef; |
2
|
|
|
|
|
|
|
|
3
|
26
|
|
|
26
|
|
181
|
use strict; |
|
26
|
|
|
|
|
54
|
|
|
26
|
|
|
|
|
740
|
|
4
|
26
|
|
|
26
|
|
150
|
use warnings; |
|
26
|
|
|
|
|
61
|
|
|
26
|
|
|
|
|
1264
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.0.5'; |
7
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
8
|
|
|
|
|
|
|
|
9
|
26
|
|
|
26
|
|
159
|
use Carp; |
|
26
|
|
|
|
|
53
|
|
|
26
|
|
|
|
|
12117
|
|
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
|
|
|
|
|
|
|
sub new { |
58
|
0
|
|
|
0
|
1
|
|
my ($inv, $colname, @defs) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my %params = (); |
61
|
0
|
0
|
0
|
|
|
|
if (@defs == 1 and ref $defs[0] eq 'HASH') { |
|
|
0
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
%params = %{ $defs[0] }; |
|
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
|
0
|
|
|
|
|
if ( uc $key ne $key ) { |
73
|
0
|
|
|
|
|
|
$params{uc $key} = delete $params{$key}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
|
my $class = ref $inv || $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
|
|
|
0
|
1
|
|
sub name { shift->{name}; } |
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
|
|
|
|
|
|
|
sub is_auto_increment { |
100
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
return ( $self->{EXTRA} =~ /auto_increment/ ) ? 1 : 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
|
|
|
|
|
|
|
sub AUTOLOAD { |
117
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
our $AUTOLOAD; |
120
|
0
|
|
|
|
|
|
$AUTOLOAD =~ /::(\w+)$/; |
121
|
0
|
|
|
|
|
|
my $key = uc($1); |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
|
return if $key eq 'DESTROY'; # do nothing |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ( exists($self->{$key}) ) { |
126
|
0
|
|
|
|
|
|
return $self->{$key}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else { |
129
|
0
|
|
|
|
|
|
confess "[$AUTOLOAD] : no such attribute"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 AUTHOR |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Egawata |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Copyright (c)2013-2014 Egawata All rights reserved. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
151
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. See L<perlartistic>. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
154
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
155
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |