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
|
|
77
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
334
|
|
6
|
11
|
|
|
11
|
|
57
|
use warnings; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
254
|
|
7
|
|
|
|
|
|
|
|
8
|
11
|
|
|
11
|
|
56
|
use Moo; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
65
|
|
9
|
11
|
|
|
11
|
|
3433
|
use Scalar::Util qw(blessed); |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
8939
|
|
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
|
596
|
my $self = shift; |
33
|
69
|
|
|
|
|
170
|
$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
|
154
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
40
|
|
|
|
|
63
|
my %info; |
53
|
|
|
|
|
|
|
|
54
|
40
|
|
|
|
|
75
|
for my $attr ( qw(name length datatype precision not_null autoincrement default_value comment) ) { |
55
|
320
|
|
|
|
|
776
|
$info{$attr} = $self->$attr(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
40
|
|
|
|
|
162
|
return \%info; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub as_string { |
63
|
11
|
|
|
11
|
1
|
9063
|
my ($self) = @_; |
64
|
|
|
|
|
|
|
|
65
|
11
|
100
|
|
|
|
172
|
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
|
|
121
|
my $self = shift; |
78
|
|
|
|
|
|
|
|
79
|
69
|
|
|
|
|
167
|
my $node = $self->node; |
80
|
|
|
|
|
|
|
|
81
|
69
|
|
|
|
|
199
|
my $id = $node->findvalue( '@id' ); |
82
|
69
|
|
|
|
|
5043
|
$self->_set_id( $id ); |
83
|
|
|
|
|
|
|
|
84
|
69
|
|
|
|
|
196
|
for my $key ( qw(name length precision comment) ) { |
85
|
276
|
|
|
|
|
808
|
my $value = $node->findvalue( './value[@key="' . $key . '"]' ); |
86
|
276
|
|
|
|
|
23839
|
my $method = $self->can( '_set_' . $key ); |
87
|
276
|
|
|
|
|
1063
|
$self->$method( $value ); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
69
|
|
|
|
|
204
|
my $datatype_internal = $node->findvalue( './link[@struct-name="db.SimpleDatatype" or @struct-name="db.UserDatatype"]' ); |
91
|
69
|
|
|
|
|
5605
|
my $datatype = $self->table->get_datatype( $datatype_internal ); |
92
|
69
|
|
|
|
|
344
|
$self->_set_datatype( $datatype->{name} ); |
93
|
69
|
|
|
|
|
227
|
$self->_set_type_info( $datatype ); |
94
|
69
|
100
|
|
|
|
192
|
$self->_set_length( $datatype->{length} ) if $datatype->{length}; |
95
|
69
|
100
|
|
|
|
177
|
$self->_set_precision( $datatype->{precision} ) if $datatype->{precision}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my %flags = map{ |
98
|
3
|
|
|
|
|
240
|
my $flag = lc $_->textContent; |
99
|
3
|
|
|
|
|
18
|
$flag => 1; |
100
|
69
|
100
|
|
|
|
122
|
}@{ $node->findnodes('./value[@key="flags"]/value') || [] }; |
|
69
|
|
|
|
|
205
|
|
101
|
69
|
|
|
|
|
5891
|
$self->_set_flags( \%flags ); |
102
|
|
|
|
|
|
|
|
103
|
69
|
|
|
|
|
239
|
my $not_null = $node->findvalue( './value[@key="isNotNull"]' ); |
104
|
69
|
|
|
|
|
6192
|
$self->_set_not_null( $not_null ); |
105
|
|
|
|
|
|
|
|
106
|
69
|
|
|
|
|
181
|
my $auto_increment = $node->findvalue( './value[@key="autoIncrement"]' ); |
107
|
69
|
|
|
|
|
5837
|
$self->_set_autoincrement( $auto_increment ); |
108
|
|
|
|
|
|
|
|
109
|
69
|
|
|
|
|
166
|
my $default = $node->findvalue( './value[@key="defaultValue"]' ); |
110
|
69
|
|
|
|
|
5975
|
$self->_set_default_value( $default ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |