line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MySQL::Workbench::Parser::Column; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A column of the ER model |
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
74
|
use strict; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
316
|
|
6
|
11
|
|
|
11
|
|
55
|
use warnings; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
246
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
53
|
use Moo; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
55
|
|
9
|
11
|
|
|
11
|
|
3395
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
8699
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has node => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
required => 1, |
17
|
|
|
|
|
|
|
isa => sub { |
18
|
|
|
|
|
|
|
blessed $_[0] && $_[0]->isa( 'XML::LibXML::Element' ); |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has table => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
required => 1, |
25
|
|
|
|
|
|
|
isa => sub { |
26
|
|
|
|
|
|
|
blessed $_[0] && $_[0]->isa( 'MySQL::Workbench::Parser::Table' ); |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub BUILD { |
32
|
69
|
|
|
69
|
1
|
589
|
my $self = shift; |
33
|
69
|
|
|
|
|
203
|
$self->_parse; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has name => ( is => 'rwp' ); |
37
|
|
|
|
|
|
|
has id => ( is => 'rwp' ); |
38
|
|
|
|
|
|
|
has length => ( is => 'rwp' ); |
39
|
|
|
|
|
|
|
has datatype => ( is => 'rwp' ); |
40
|
|
|
|
|
|
|
has precision => ( is => 'rwp' ); |
41
|
|
|
|
|
|
|
has not_null => ( is => 'rwp' ); |
42
|
|
|
|
|
|
|
has autoincrement => ( is => 'rwp' ); |
43
|
|
|
|
|
|
|
has default_value => ( is => 'rwp' ); |
44
|
|
|
|
|
|
|
has comment => ( is => 'rwp' ); |
45
|
|
|
|
|
|
|
has type_info => ( is => 'rwp' ); |
46
|
|
|
|
|
|
|
has flags => ( is => 'rwp' ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub as_hash { |
50
|
40
|
|
|
40
|
1
|
160
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
40
|
|
|
|
|
64
|
my %info; |
53
|
|
|
|
|
|
|
|
54
|
40
|
|
|
|
|
90
|
for my $attr ( qw(name length datatype precision not_null autoincrement default_value comment) ) { |
55
|
320
|
|
|
|
|
784
|
$info{$attr} = $self->$attr(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
40
|
|
|
|
|
162
|
return \%info; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub as_string { |
63
|
11
|
|
|
11
|
1
|
8828
|
my ($self) = @_; |
64
|
|
|
|
|
|
|
|
65
|
11
|
100
|
|
|
|
156
|
my $info = sprintf "%s %s%s%s%s%s", |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->name, |
67
|
|
|
|
|
|
|
$self->datatype, |
68
|
|
|
|
|
|
|
( $self->length > 0 ? "(" . $self->length . ")" : '' ), |
69
|
|
|
|
|
|
|
( $self->not_null ? ' NOT NULL' : '' ), |
70
|
|
|
|
|
|
|
( $self->autoincrement ? ' AUTOINCREMENT' : '' ), |
71
|
|
|
|
|
|
|
$self->default_value; |
72
|
|
|
|
|
|
|
|
73
|
11
|
|
|
|
|
33
|
return $info; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _parse { |
77
|
69
|
|
|
69
|
|
120
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
69
|
|
|
|
|
173
|
my $node = $self->node; |
80
|
|
|
|
|
|
|
|
81
|
69
|
|
|
|
|
189
|
my $id = $node->findvalue( '@id' ); |
82
|
69
|
|
|
|
|
5077
|
$self->_set_id( $id ); |
83
|
|
|
|
|
|
|
|
84
|
69
|
|
|
|
|
201
|
for my $key ( qw(name length precision comment) ) { |
85
|
276
|
|
|
|
|
796
|
my $value = $node->findvalue( './value[@key="' . $key . '"]' ); |
86
|
276
|
|
|
|
|
23523
|
my $method = $self->can( '_set_' . $key ); |
87
|
276
|
|
|
|
|
983
|
$self->$method( $value ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
69
|
|
|
|
|
194
|
my $datatype_internal = $node->findvalue( './link[@struct-name="db.SimpleDatatype" or @struct-name="db.UserDatatype"]' ); |
91
|
69
|
|
|
|
|
5582
|
my $datatype = $self->table->get_datatype( $datatype_internal ); |
92
|
69
|
|
|
|
|
327
|
$self->_set_datatype( $datatype->{name} ); |
93
|
69
|
|
|
|
|
188
|
$self->_set_type_info( $datatype ); |
94
|
69
|
100
|
|
|
|
196
|
$self->_set_length( $datatype->{length} ) if $datatype->{length}; |
95
|
69
|
100
|
|
|
|
171
|
$self->_set_precision( $datatype->{precision} ) if $datatype->{precision}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %flags = map{ |
98
|
3
|
|
|
|
|
234
|
my $flag = lc $_->textContent; |
99
|
3
|
|
|
|
|
15
|
$flag => 1; |
100
|
69
|
100
|
|
|
|
116
|
}@{ $node->findnodes('./value[@key="flags"]/value') || [] }; |
|
69
|
|
|
|
|
211
|
|
101
|
69
|
|
|
|
|
5992
|
$self->_set_flags( \%flags ); |
102
|
|
|
|
|
|
|
|
103
|
69
|
|
|
|
|
224
|
my $not_null = $node->findvalue( './value[@key="isNotNull"]' ); |
104
|
69
|
|
|
|
|
6147
|
$self->_set_not_null( $not_null ); |
105
|
|
|
|
|
|
|
|
106
|
69
|
|
|
|
|
187
|
my $auto_increment = $node->findvalue( './value[@key="autoIncrement"]' ); |
107
|
69
|
|
|
|
|
5760
|
$self->_set_autoincrement( $auto_increment ); |
108
|
|
|
|
|
|
|
|
109
|
69
|
|
|
|
|
174
|
my $default = $node->findvalue( './value[@key="defaultValue"]' ); |
110
|
69
|
|
|
|
|
6031
|
$self->_set_default_value( $default ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |