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
|
|
62
|
use strict; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
263
|
|
6
|
11
|
|
|
11
|
|
42
|
use warnings; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
202
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
40
|
use Moo; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
46
|
|
9
|
11
|
|
|
11
|
|
2761
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
7069
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
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
|
458
|
my $self = shift; |
33
|
69
|
|
|
|
|
141
|
$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
|
53
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
40
|
|
|
|
|
126
|
my %info; |
53
|
|
|
|
|
|
|
|
54
|
40
|
|
|
|
|
74
|
for my $attr ( qw(name length datatype precision not_null autoincrement default_value comment) ) { |
55
|
320
|
|
|
|
|
672
|
$info{$attr} = $self->$attr(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
40
|
|
|
|
|
97
|
return \%info; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub as_string { |
63
|
11
|
|
|
11
|
1
|
7759
|
my ($self) = @_; |
64
|
|
|
|
|
|
|
|
65
|
11
|
100
|
|
|
|
119
|
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
|
|
|
|
|
59
|
return $info; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _parse { |
77
|
69
|
|
|
69
|
|
102
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
69
|
|
|
|
|
171
|
my $node = $self->node; |
80
|
|
|
|
|
|
|
|
81
|
69
|
|
|
|
|
164
|
my $id = $node->findvalue( '@id' ); |
82
|
69
|
|
|
|
|
4066
|
$self->_set_id( $id ); |
83
|
|
|
|
|
|
|
|
84
|
69
|
|
|
|
|
145
|
for my $key ( qw(name length precision comment) ) { |
85
|
276
|
|
|
|
|
635
|
my $value = $node->findvalue( './value[@key="' . $key . '"]' ); |
86
|
276
|
|
|
|
|
19104
|
my $method = $self->can( '_set_' . $key ); |
87
|
276
|
|
|
|
|
790
|
$self->$method( $value ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
69
|
|
|
|
|
168
|
my $datatype_internal = $node->findvalue( './link[@struct-name="db.SimpleDatatype" or @struct-name="db.UserDatatype"]' ); |
91
|
69
|
|
|
|
|
4847
|
my $datatype = $self->table->get_datatype( $datatype_internal ); |
92
|
69
|
|
|
|
|
278
|
$self->_set_datatype( $datatype->{name} ); |
93
|
69
|
|
|
|
|
166
|
$self->_set_type_info( $datatype ); |
94
|
69
|
100
|
|
|
|
148
|
$self->_set_length( $datatype->{length} ) if $datatype->{length}; |
95
|
69
|
100
|
|
|
|
146
|
$self->_set_precision( $datatype->{precision} ) if $datatype->{precision}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %flags = map{ |
98
|
3
|
|
|
|
|
190
|
my $flag = lc $_->textContent; |
99
|
3
|
|
|
|
|
13
|
$flag => 1; |
100
|
69
|
100
|
|
|
|
98
|
}@{ $node->findnodes('./value[@key="flags"]/value') || [] }; |
|
69
|
|
|
|
|
165
|
|
101
|
69
|
|
|
|
|
4857
|
$self->_set_flags( \%flags ); |
102
|
|
|
|
|
|
|
|
103
|
69
|
|
|
|
|
182
|
my $not_null = $node->findvalue( './value[@key="isNotNull"]' ); |
104
|
69
|
|
|
|
|
5008
|
$self->_set_not_null( $not_null ); |
105
|
|
|
|
|
|
|
|
106
|
69
|
|
|
|
|
142
|
my $auto_increment = $node->findvalue( './value[@key="autoIncrement"]' ); |
107
|
69
|
|
|
|
|
4742
|
$self->_set_autoincrement( $auto_increment ); |
108
|
|
|
|
|
|
|
|
109
|
69
|
|
|
|
|
142
|
my $default = $node->findvalue( './value[@key="defaultValue"]' ); |
110
|
69
|
|
|
|
|
5161
|
$self->_set_default_value( $default ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |