line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AutoCode::Schema; |
2
|
5
|
|
|
5
|
|
18174
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
181
|
|
3
|
5
|
|
|
5
|
|
26
|
use vars qw(@ISA); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
227
|
|
4
|
5
|
|
|
5
|
|
632
|
use AutoCode::Root; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
our @ISA=qw(AutoCode::Root); |
6
|
|
|
|
|
|
|
our %PLURALS; |
7
|
5
|
|
|
5
|
|
753
|
use AutoCode::ModuleModel; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
34
|
|
8
|
|
|
|
|
|
|
use AutoCode::AccessorMaker( |
9
|
5
|
|
|
|
|
39
|
'$'=>[qw(plurals modules package_prefix)], |
10
|
|
|
|
|
|
|
'@'=>[qw(friendship)] |
11
|
5
|
|
|
5
|
|
30
|
); |
|
5
|
|
|
|
|
15
|
|
12
|
5
|
|
|
5
|
|
2346
|
use AutoCode::Friendship; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
41
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
642
|
use AutoCode::Plurality; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
37
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _initialize { |
17
|
5
|
|
|
5
|
|
73
|
my ($self, @args)=@_; |
18
|
5
|
|
|
|
|
46
|
$self->SUPER::_initialize(@args); |
19
|
|
|
|
|
|
|
|
20
|
5
|
|
|
|
|
55
|
my ($modules, $package_prefix, $plurals, $modules_type_grouped)= |
21
|
|
|
|
|
|
|
$self->_rearrange( |
22
|
|
|
|
|
|
|
[qw(MODULES PACKAGE_PREFIX PLURALS modules_type_grouped)], @args); |
23
|
|
|
|
|
|
|
|
24
|
5
|
50
|
|
|
|
53
|
(ref($modules) eq 'HASH') and $self->modules($modules); |
25
|
5
|
50
|
|
|
|
17
|
if(defined $modules_type_grouped){ |
26
|
|
|
|
|
|
|
# print STDERR "FOUND modules_type_grouped\n"; |
27
|
0
|
0
|
|
|
|
0
|
$modules= {} unless defined $modules; |
28
|
0
|
0
|
|
|
|
0
|
$self->throw('modules_type_grouped must be a hash ref') |
29
|
|
|
|
|
|
|
unless ref($modules_type_grouped) eq 'HASH'; |
30
|
0
|
|
|
|
|
0
|
foreach my $module_name(keys %$modules_type_grouped){ |
31
|
0
|
0
|
|
|
|
0
|
$self->throw("one key '$module_name' in modules_type_grouped has been defined\nCURRENT KEYS:\t". join("\t", keys %$modules)) |
32
|
|
|
|
|
|
|
if exists $modules->{$module_name}; |
33
|
0
|
|
|
|
|
0
|
my $module_type_grouped = $modules_type_grouped->{$module_name}; |
34
|
0
|
|
|
|
|
0
|
my %module; |
35
|
0
|
|
|
|
|
0
|
foreach my $field_type (keys %$module_type_grouped){ |
36
|
0
|
|
|
|
|
0
|
foreach (@{$module_type_grouped->{$field_type}}){ |
|
0
|
|
|
|
|
0
|
|
37
|
0
|
|
|
|
|
0
|
$module{$_}= $field_type; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
0
|
$modules->{$module_name}= \%module; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
0
|
$self->modules($modules); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
11
|
our $FRIENDSHIP_TYPE='~friends'; |
46
|
5
|
50
|
|
|
|
22
|
if(exists $modules->{$FRIENDSHIP_TYPE}){ |
47
|
5
|
|
|
|
|
12
|
my $friends=$modules->{$FRIENDSHIP_TYPE}; |
48
|
5
|
|
|
|
|
15
|
delete $modules->{$FRIENDSHIP_TYPE}; |
49
|
5
|
|
|
|
|
19
|
foreach my $friend(keys %$friends){ |
50
|
5
|
|
|
|
|
27
|
my @peers=split /-/, $friend; |
51
|
5
|
|
|
|
|
13
|
my $extras=$friends->{$friend}; |
52
|
5
|
|
|
|
|
38
|
$extras=~ s/;$//; |
53
|
5
|
|
|
|
|
18
|
my @extras=split /;/, $extras; |
54
|
5
|
|
|
|
|
90
|
my $friendship = AutoCode::Friendship->new( |
55
|
|
|
|
|
|
|
-peer_string => $friend, |
56
|
|
|
|
|
|
|
-peers => \@peers, |
57
|
|
|
|
|
|
|
-extras => \@extras |
58
|
|
|
|
|
|
|
); |
59
|
5
|
|
|
|
|
56
|
$self->add_friendship($friendship); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
40
|
$self->package_prefix($package_prefix); |
64
|
5
|
|
|
|
|
30
|
$self->plurals({}); |
65
|
5
|
50
|
|
|
|
21
|
if(defined $plurals){ |
66
|
5
|
50
|
|
|
|
20
|
if(ref($plurals) eq 'HASH'){ |
67
|
|
|
|
|
|
|
# not directly assign to the package variable, avoiding overwrite |
68
|
5
|
|
|
|
|
27
|
$self->plurals($plurals); |
69
|
5
|
|
|
|
|
17
|
foreach (keys %$plurals){ |
70
|
5
|
|
|
|
|
42
|
AutoCode::Plurality->add_plural($_, $plurals->{$_}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
}else{ |
73
|
0
|
|
|
|
|
0
|
$self->throw("plurals must be a hash reference"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} # else{ %PLURALS=();} wrongly to initialize the package variable. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Only be invoked by ModuleModel. |
80
|
|
|
|
|
|
|
# |
81
|
|
|
|
|
|
|
sub _get_module_definition { |
82
|
14
|
|
|
14
|
|
24
|
my ($self, $type)=@_; |
83
|
14
|
|
|
|
|
49
|
$self->_check_type($type); |
84
|
14
|
|
|
|
|
40
|
return $self->modules->{$type}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub get_all_types { |
88
|
0
|
|
|
0
|
0
|
0
|
my $self=shift; |
89
|
0
|
|
|
|
|
0
|
return grep !/^\W/, keys %{$self->modules}; |
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get_friends { |
93
|
0
|
|
|
0
|
0
|
0
|
my $friends=shift->modules->{'~friends'}; |
94
|
0
|
0
|
|
|
|
0
|
return (defined $friends)? @$friends : []; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub dependence { |
98
|
0
|
|
|
0
|
0
|
0
|
my $self=shift; |
99
|
0
|
|
|
|
|
0
|
my %dependance=(); |
100
|
0
|
|
|
|
|
0
|
my %modules=%{$self->modules}; |
|
0
|
|
|
|
|
0
|
|
101
|
0
|
|
|
|
|
0
|
my @types = keys %modules; |
102
|
0
|
|
|
|
|
0
|
foreach my $type(@types){ |
103
|
0
|
|
|
|
|
0
|
my $module = $self->get_module_model($type); |
104
|
0
|
|
|
|
|
0
|
foreach my $tag ($module->get_all_value_attributes){ |
105
|
0
|
|
|
|
|
0
|
my ($context, $kind, $content, $required) = |
106
|
|
|
|
|
|
|
$module->_classify_value_attribute($tag); |
107
|
0
|
0
|
|
|
|
0
|
if($kind eq 'M'){ |
108
|
0
|
0
|
|
|
|
0
|
$dependance{$type} = {} unless exists $dependance{$type}; |
109
|
0
|
|
|
|
|
0
|
$dependance{$type}->{$content} = [$context, $tag]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
return %dependance; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub find_friends { |
118
|
18
|
|
|
18
|
0
|
31
|
my ($self, $module)=@_; |
119
|
18
|
|
33
|
|
|
76
|
$module = ref($module) || $module; |
120
|
18
|
|
|
|
|
24
|
my @friends; # to return |
121
|
18
|
|
|
|
|
69
|
my @friendship=$self->get_friendships; |
122
|
18
|
|
|
|
|
53
|
foreach my $friendship ($self->get_friendships){ |
123
|
18
|
100
|
|
|
|
97
|
if(grep /^$module$/, $friendship->get_peers){ |
124
|
8
|
|
|
|
|
30
|
push @friends, grep !/^$module$/, $friendship->get_peers; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
18
|
|
|
|
|
70
|
return @friends; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub has_a { |
131
|
0
|
|
|
0
|
0
|
0
|
my ($self, $type)=@_; |
132
|
0
|
|
|
|
|
0
|
my %dependence = $self->dependence; |
133
|
0
|
|
|
|
|
0
|
return ${$dependence{$type}}; |
|
0
|
|
|
|
|
0
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub fks { |
137
|
0
|
|
|
0
|
0
|
0
|
my ($self)=@_; |
138
|
0
|
|
|
|
|
0
|
my %has_a=$self->dependence; |
139
|
0
|
|
|
|
|
0
|
my %fks; |
140
|
0
|
|
|
|
|
0
|
foreach my $type(keys %has_a){ |
141
|
0
|
|
|
|
|
0
|
my %type=%{$has_a{$type}}; |
|
0
|
|
|
|
|
0
|
|
142
|
0
|
|
|
|
|
0
|
foreach(keys %type){ |
143
|
0
|
0
|
|
|
|
0
|
$fks{$_}={} unless exists $fks{$_}; |
144
|
0
|
|
|
|
|
0
|
$fks{$_}->{$type}=$type{$_}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
0
|
return %fks; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
our %MODULE_MODELS; |
151
|
|
|
|
|
|
|
sub get_module_model { |
152
|
36
|
|
|
36
|
0
|
55
|
my ($self, $type)=@_; |
153
|
36
|
100
|
|
|
|
164
|
return $MODULE_MODELS{$type} if exists $MODULE_MODELS{$type}; |
154
|
14
|
|
|
|
|
111
|
my $model=AutoCode::ModuleModel->new( |
155
|
|
|
|
|
|
|
-schema => $self, |
156
|
|
|
|
|
|
|
-type => $type |
157
|
|
|
|
|
|
|
); |
158
|
14
|
|
|
|
|
41
|
$MODULE_MODELS{$type} = $model; |
159
|
14
|
|
|
|
|
42
|
return $model; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _check_type { |
163
|
14
|
|
|
14
|
|
20
|
my ($self, $type)=@_; |
164
|
14
|
50
|
|
|
|
67
|
$self->throw("[$type] does not exist in the schema") |
165
|
|
|
|
|
|
|
unless exists $self->modules->{$type}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub get_plural { |
169
|
28
|
|
|
28
|
0
|
39
|
my ($self, $singular)=@_; |
170
|
28
|
|
|
|
|
67
|
my $plurals=$self->plurals; |
171
|
28
|
100
|
|
|
|
198
|
return (exists $plurals->{$singular})?$plurals->{$singular}:"${singular}s"; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub ref_plural { |
175
|
0
|
|
|
0
|
0
|
|
my ($self, $singular)=@_; |
176
|
0
|
|
|
|
|
|
return [$singular, $self->get_plural($singular)]; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |