line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::PML::Schema::Import; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
39
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
158
|
|
4
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
147
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
30
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
236
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
6
|
|
|
6
|
|
95
|
$VERSION='2.24'; # version template |
9
|
|
|
|
|
|
|
} |
10
|
6
|
|
|
6
|
|
26
|
no warnings 'uninitialized'; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
156
|
|
11
|
6
|
|
|
6
|
|
26
|
use Carp; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
304
|
|
12
|
6
|
|
|
6
|
|
2913
|
use URI; |
|
6
|
|
|
|
|
24669
|
|
|
6
|
|
|
|
|
169
|
|
13
|
6
|
|
|
6
|
|
34
|
use Treex::PML::Schema::Constants; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
525
|
|
14
|
6
|
|
|
6
|
|
36
|
use Encode; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
422
|
|
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
6
|
|
31
|
use base qw(Treex::PML::Schema::XMLNode); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
4858
|
|
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
1
|
0
|
sub get_decl_type { return(PML_IMPORT_DECL); } |
19
|
0
|
|
|
0
|
1
|
0
|
sub get_decl_type_str { return('import'); } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub schema { |
22
|
16
|
|
|
16
|
0
|
40
|
my ($self)=@_; |
23
|
16
|
|
|
|
|
83
|
$self=$self->{-parent} while $self->{-parent}; |
24
|
16
|
|
|
|
|
36
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub simplify { |
28
|
16
|
|
|
16
|
1
|
43
|
my ($import,$opts)=@_; |
29
|
16
|
|
|
|
|
106
|
my $target = $import->schema; |
30
|
16
|
|
50
|
|
|
77
|
my $base_url = $target->{URL}||''; |
31
|
16
|
|
|
|
|
123
|
my $parent = $import->{-parent}; # FIXME: for templates |
32
|
|
|
|
|
|
|
return if |
33
|
|
|
|
|
|
|
($parent->get_decl_type == PML_TEMPLATE_DECL and $opts->{no_template_import} or |
34
|
16
|
50
|
66
|
|
|
58
|
$parent->get_decl_type == PML_SCHEMA_DECL and $opts->{no_import}); |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
35
|
16
|
50
|
|
|
|
55
|
die "Missing 'schema' attribute on element in $base_url!" unless $import->{schema}; |
36
|
|
|
|
|
|
|
|
37
|
16
|
|
50
|
|
|
53
|
$opts->{schemas}||={}; |
38
|
16
|
|
|
|
|
78
|
my $url = URI->new(Encode::encode_utf8($import->{schema})); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $schema = ref($target)->new({ |
41
|
48
|
|
|
|
|
128
|
(map { ($_=>$opts->{$_}) } qw(schemas use_resources validate)), |
42
|
|
|
|
|
|
|
filename => $url, |
43
|
|
|
|
|
|
|
base_url => $base_url, |
44
|
|
|
|
|
|
|
imported => 1, |
45
|
|
|
|
|
|
|
(map { |
46
|
16
|
100
|
|
|
|
1081
|
exists($import->{$_}) ? ( $_ => $import->{$_} ) : () |
|
48
|
|
|
|
|
187
|
|
47
|
|
|
|
|
|
|
} qw(revision minimal_revision maximal_revision)), |
48
|
|
|
|
|
|
|
revision_error => "Error importing schema %f to $base_url - revision mismatch: %e" |
49
|
|
|
|
|
|
|
}); |
50
|
16
|
100
|
33
|
|
|
753
|
if ((!exists($import->{type}) and |
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
51
|
|
|
|
|
|
|
!exists($import->{template}) and |
52
|
|
|
|
|
|
|
!exists($import->{root}) |
53
|
|
|
|
|
|
|
) or defined($import->{type}) and $import->{type} eq '*') { |
54
|
|
|
|
|
|
|
# print STDERR "IMPORTING *\n"; |
55
|
3
|
50
|
|
|
|
15
|
if (ref $schema->{type}) { |
56
|
3
|
|
100
|
|
|
15
|
$parent->{type}||={}; |
57
|
3
|
|
|
|
|
6
|
foreach my $name (keys(%{$schema->{type}})) { |
|
3
|
|
|
|
|
22
|
|
58
|
16
|
50
|
|
|
|
55
|
unless (exists $parent->{type}{$name}) { |
59
|
16
|
|
|
|
|
64
|
$parent->{type}{$name}=$parent->copy_decl($schema->{type}{$name}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} else { |
64
|
13
|
|
|
|
|
33
|
my $name = $import->{type}; |
65
|
|
|
|
|
|
|
# print STDERR "IMPORTING $name\n"; |
66
|
13
|
50
|
|
|
|
48
|
if (ref($schema->{type})) { |
67
|
13
|
|
|
|
|
58
|
$import->_import_type($parent,$schema,$name); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
16
|
100
|
33
|
|
|
145
|
if ((!exists($import->{type}) and |
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
71
|
|
|
|
|
|
|
!exists($import->{template}) and |
72
|
|
|
|
|
|
|
!exists($import->{root}) |
73
|
|
|
|
|
|
|
) or defined($import->{template}) and $import->{template} eq '*') { |
74
|
3
|
50
|
|
|
|
13
|
if (ref $schema->{template}) { |
75
|
0
|
|
0
|
|
|
0
|
$parent->{template}||={}; |
76
|
0
|
|
|
|
|
0
|
foreach my $name (keys(%{$schema->{template}})) { |
|
0
|
|
|
|
|
0
|
|
77
|
0
|
0
|
|
|
|
0
|
unless (exists $parent->{template}{$name}) { |
78
|
0
|
|
|
|
|
0
|
$parent->{template}{$name}=$parent->copy_decl($schema->{template}{$name}); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} else { |
83
|
13
|
|
|
|
|
31
|
my $name = $import->{template}; |
84
|
13
|
50
|
|
|
|
49
|
if (ref($schema->{template})) { |
85
|
0
|
0
|
|
|
|
0
|
unless (exists $parent->{template}{$name}) { |
86
|
0
|
|
|
|
|
0
|
$parent->{template}{$name}=$parent->copy_decl($schema->{template}{$name}); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
16
|
50
|
100
|
|
|
135
|
if (((!exists($import->{type}) and |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
91
|
|
|
|
|
|
|
!exists($import->{template}) and |
92
|
|
|
|
|
|
|
!exists($import->{root}) |
93
|
|
|
|
|
|
|
) or defined($import->{root}) and $import->{root} eq '1') and !exists($parent->{root}) and $schema->{root}) { |
94
|
3
|
|
|
|
|
15
|
$parent->{root} = $parent->copy_decl($schema->{root}); |
95
|
|
|
|
|
|
|
} |
96
|
16
|
|
|
|
|
65
|
return $schema; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _import_type { |
100
|
13
|
|
|
13
|
|
42
|
my ($self,$target,$src_schema, $name) = @_; |
101
|
13
|
50
|
|
|
|
56
|
unless (exists $src_schema->{type}{$name}) { |
102
|
0
|
|
|
|
|
0
|
croak "Cannot import type '$name' from '$src_schema->{URL}' to '$target->{URL}': type not declared in the source schema\n"; |
103
|
|
|
|
|
|
|
} |
104
|
13
|
|
|
|
|
32
|
my $type = $src_schema->{type}{$name}; |
105
|
13
|
|
|
|
|
43
|
my %referred = ($name => $type); |
106
|
13
|
|
|
|
|
65
|
$src_schema->_get_referred_types($type,\%referred); |
107
|
13
|
|
|
|
|
90
|
foreach my $n (keys %referred) { |
108
|
22
|
100
|
|
|
|
81
|
unless (exists $target->{type}{$n}) { |
109
|
18
|
|
|
|
|
91
|
$target->{type}{$n}=$target->copy_decl($referred{$n}); |
110
|
|
|
|
|
|
|
} else { |
111
|
|
|
|
|
|
|
# print STDERR "already there\n"; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
__END__ |