1 |
#!/usr/bin/perl -w |
2 |
use strict; |
3 |
|
4 |
=head1 NAME |
5 |
|
6 |
mkdisdump.pl - Generating Perl Module Documentation Source |
7 |
|
8 |
=head1 SYNOPSIS |
9 |
|
10 |
perl path/to/mkdisdump.pl input.cdis \ |
11 |
{--module-name=ModuleName | --module-uri=module-uri} \ |
12 |
[--for=for-uri] [options] > ModuleName.pm |
13 |
perl path/to/cdis2pm.pl --help |
14 |
|
15 |
=head1 DESCRIPTION |
16 |
|
17 |
The C<cdis2pm> script generates a Perl module from a compiled "dis" |
18 |
("cdis") file. It is intended to be used to generate a manakai |
19 |
DOM Perl module files, although it might be useful for other purpose. |
20 |
|
21 |
This script is part of manakai. |
22 |
|
23 |
=cut |
24 |
|
25 |
use Message::DOM::DOMLS; |
26 |
use Message::Util::DIS::DISDump; |
27 |
use Message::Util::QName::Filter { |
28 |
ddel => q<http://suika.fam.cx/~wakaba/archive/2005/disdoc#>, |
29 |
ddoct => q<http://suika.fam.cx/~wakaba/archive/2005/8/disdump-xslt#>, |
30 |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
31 |
dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->, |
32 |
dis2pm => q<http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm#>, |
33 |
DISCore => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Core#>, |
34 |
DISLang => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Lang#>, |
35 |
DISPerl => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Perl#>, |
36 |
disPerl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--Perl-->, |
37 |
DOMCore => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
38 |
DOMEvents => q<http://suika.fam.cx/~wakaba/archive/2004/dom/events#>, |
39 |
DOMLS => q<http://suika.fam.cx/~wakaba/archive/2004/dom/ls#>, |
40 |
DOMMain => q<http://suika.fam.cx/~wakaba/archive/2004/dom/main#>, |
41 |
DOMXML => q<http://suika.fam.cx/~wakaba/archive/2004/dom/xml#>, |
42 |
dump => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#DISDump/>, |
43 |
DX => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/DOMException#>, |
44 |
ecore => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/Core/>, |
45 |
html5 => q<http://www.w3.org/1999/xhtml>, |
46 |
infoset => q<http://www.w3.org/2001/04/infoset#>, |
47 |
lang => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#>, |
48 |
Perl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl-->, |
49 |
license => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/license#>, |
50 |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
51 |
Markup => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup#>, |
52 |
MDOMX => q<http://suika.fam.cx/~wakaba/archive/2004/8/4/manakai-dom-exception#>, |
53 |
owl => q<http://www.w3.org/2002/07/owl#>, |
54 |
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
55 |
rdf => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>, |
56 |
rdfs => q<http://www.w3.org/2000/01/rdf-schema#>, |
57 |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
58 |
TreeCore => q<>, |
59 |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
60 |
xhtml1 => q<http://www.w3.org/1999/xhtml>, |
61 |
xhtml2 => q<http://www.w3.org/2002/06/xhtml2>, |
62 |
xml => q<http://www.w3.org/XML/1998/namespace>, |
63 |
xmlns => q<http://www.w3.org/2000/xmlns/>, |
64 |
}; |
65 |
|
66 |
=head1 OPTIONS |
67 |
|
68 |
=over 4 |
69 |
|
70 |
=item --for=I<for-uri> (Optional) |
71 |
|
72 |
Specifies the "For" URI reference for which the outputed module is. |
73 |
If this parameter is ommitted, the default "For" URI reference |
74 |
for the module, if any, or the C<ManakaiDOM:all> is assumed. |
75 |
|
76 |
=item --help |
77 |
|
78 |
Shows the help message. |
79 |
|
80 |
=item --module-uri=I<module-uri> |
81 |
|
82 |
A URI reference that identifies a module to output. Either |
83 |
C<--module-name> or C<--module-uri> is required. |
84 |
|
85 |
=item --verbose / --noverbose (default) |
86 |
|
87 |
Whether a verbose message mode should be selected or not. |
88 |
|
89 |
=item --with-implementators-note / --nowith-implementators-note (default) |
90 |
|
91 |
Whether the implemetator's notes should also be included |
92 |
in the result or not. |
93 |
|
94 |
=back |
95 |
|
96 |
=cut |
97 |
|
98 |
use Getopt::Long; |
99 |
use Pod::Usage; |
100 |
use Storable; |
101 |
use Message::Util::Error; |
102 |
my %Opt = ( |
103 |
module_uri => {}, |
104 |
); |
105 |
GetOptions ( |
106 |
'for=s' => \$Opt{For}, |
107 |
'help' => \$Opt{help}, |
108 |
'module-uri=s' => sub { |
109 |
shift; |
110 |
$Opt{module_uri}->{+shift} = 1; |
111 |
}, |
112 |
'with-implementators-note' => \$Opt{with_impl_note}, |
113 |
) or pod2usage (2); |
114 |
pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help}; |
115 |
$Opt{file_name} = shift; |
116 |
pod2usage ({-exitval => 2, -verbose => 0}) unless $Opt{file_name}; |
117 |
pod2usage (2) unless keys %{$Opt{module_uri}}; |
118 |
|
119 |
sub status_msg ($) { |
120 |
my $s = shift; |
121 |
$s .= "\n" unless $s =~ /\n$/; |
122 |
print STDERR $s; |
123 |
} |
124 |
|
125 |
sub status_msg_ ($) { |
126 |
my $s = shift; |
127 |
print STDERR $s; |
128 |
} |
129 |
|
130 |
sub verbose_msg ($) { |
131 |
my $s = shift; |
132 |
$s .= "\n" unless $s =~ /\n$/; |
133 |
print STDERR $s; |
134 |
} |
135 |
|
136 |
sub verbose_msg_ ($) { |
137 |
my $s = shift; |
138 |
print STDERR $s; |
139 |
} |
140 |
|
141 |
my $impl = $Message::DOM::ImplementationRegistry->get_implementation |
142 |
({ |
143 |
ExpandedURI q<ManakaiDOM:Minimum> => '3.0', |
144 |
'+' . ExpandedURI q<DOMLS:LS> => '3.0', |
145 |
'+' . ExpandedURI q<DIS:Doc> => '2.0', |
146 |
ExpandedURI q<DIS:Dump> => '1.0', |
147 |
}); |
148 |
|
149 |
## -- Load input dac database file |
150 |
status_msg_ qq<Opening dac file "$Opt{file_name}"...>; |
151 |
our $db = $impl->get_feature (ExpandedURI q<DIS:Core> => '1.0') |
152 |
->pl_load_dis_database ($Opt{file_name}); |
153 |
status_msg qq<done\n>; |
154 |
|
155 |
our %ReferredResource; |
156 |
our %ClassMembers; |
157 |
our %ClassInheritance; |
158 |
our @ClassInheritance; |
159 |
our %ClassImplements; |
160 |
|
161 |
sub append_module_documentation (%) { |
162 |
my %opt = @_; |
163 |
my $section = $opt{result_parent}->create_module ($opt{source_resource}->uri); |
164 |
|
165 |
add_uri ($opt{source_resource} => $section); |
166 |
|
167 |
my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name; |
168 |
if (defined $pl_full_name) { |
169 |
$section->perl_package_name ($pl_full_name); |
170 |
|
171 |
my $path = $opt{source_resource}->get_property_text |
172 |
(ExpandedURI q<dis:FileName>, $pl_full_name); |
173 |
$path =~ s#::#/#g; |
174 |
$section->resource_file_path_stem ($path); |
175 |
|
176 |
$section->set_attribute_ns |
177 |
(ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x ($path =~ tr#/#/#)); |
178 |
$pl_full_name =~ s/.*:://g; |
179 |
$section->perl_name ($pl_full_name); |
180 |
} |
181 |
|
182 |
append_description (source_resource => $opt{source_resource}, |
183 |
result_parent => $section); |
184 |
|
185 |
if ($opt{is_partial}) { |
186 |
$section->resource_is_partial (1); |
187 |
return; |
188 |
} |
189 |
|
190 |
for my $rres (@{$opt{source_resource}->get_property_resource_list |
191 |
(ExpandedURI q<DIS:resource>)}) { |
192 |
if ($rres->owner_module eq $opt{source_resource} and## Defined in this module |
193 |
not ($ReferredResource{$rres->uri} < 0)) { |
194 |
## TODO: Modification required to support modplans |
195 |
status_msg_ "*"; |
196 |
if ($rres->is_type_uri (ExpandedURI q<ManakaiDOM:Class>)) { |
197 |
append_class_documentation |
198 |
(result_parent => $section, |
199 |
source_resource => $rres); |
200 |
} elsif ($rres->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) { |
201 |
append_interface_documentation |
202 |
(result_parent => $section, |
203 |
source_resource => $rres); |
204 |
} elsif ($rres->is_type_uri (ExpandedURI q<DISCore:AbstractDataType>)) { |
205 |
append_datatype_documentation |
206 |
(result_parent => $section, |
207 |
source_resource => $rres); |
208 |
} |
209 |
} else { ## Aliases |
210 |
# |
211 |
} |
212 |
} |
213 |
status_msg ""; |
214 |
} # append_module_documentation |
215 |
|
216 |
sub append_datatype_documentation (%) { |
217 |
my %opt = @_; |
218 |
my $section = $opt{result_parent}->create_data_type |
219 |
($opt{source_resource}->uri); |
220 |
|
221 |
add_uri ($opt{source_resource} => $section); |
222 |
|
223 |
my $uri = $opt{source_resource}->name_uri; |
224 |
if ($uri) { |
225 |
my $fu = $opt{source_resource}->for_uri; |
226 |
unless ($fu eq ExpandedURI q<ManakaiDOM:all>) { |
227 |
$fu =~ /([\w.-]+)[^\w.-]*$/; |
228 |
$uri .= '-' . $1; |
229 |
} |
230 |
} else { |
231 |
$opt{source_resource}->uri; |
232 |
} |
233 |
$uri =~ s#\b(\d\d\d\d+)/(\d\d?)/(\d\d?)#sprintf '%04d%02d%02d', $1, $2, $3#ge; |
234 |
my @file = map {s/[^\w-]/_/g; $_} split m{[/:#?]+}, $uri; |
235 |
|
236 |
$section->resource_file_path_stem (join '/', @file); |
237 |
$section->set_attribute_ns |
238 |
(ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x (@file - 1)); |
239 |
|
240 |
my $docr = $opt{source_resource}->get_feature (ExpandedURI q<DIS:Doc>, '2.0'); |
241 |
my $label = $docr->get_label ($section->owner_document); |
242 |
if ($label) { |
243 |
$section->create_label->append_child (transform_disdoc_tree ($label)); |
244 |
} |
245 |
|
246 |
append_description (source_resource => $opt{source_resource}, |
247 |
result_parent => $section); |
248 |
|
249 |
if ($opt{is_partial}) { |
250 |
$section->resource_is_partial (1); |
251 |
return; |
252 |
} |
253 |
|
254 |
append_subclassof (source_resource => $opt{source_resource}, |
255 |
result_parent => $section); |
256 |
} # append_datatype_documentation |
257 |
|
258 |
sub append_interface_documentation (%) { |
259 |
my %opt = @_; |
260 |
my $section = $opt{result_parent}->create_interface |
261 |
(my $class_uri = $opt{source_resource}->uri); |
262 |
push @ClassInheritance, $class_uri; |
263 |
|
264 |
add_uri ($opt{source_resource} => $section); |
265 |
|
266 |
my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name; |
267 |
if (defined $pl_full_name) { |
268 |
$section->perl_package_name ($pl_full_name); |
269 |
|
270 |
my $path = $opt{source_resource}->get_property_text |
271 |
(ExpandedURI q<dis:FileName>, $pl_full_name); |
272 |
$path =~ s#::#/#g; |
273 |
$section->resource_file_path_stem ($path); |
274 |
|
275 |
$section->set_attribute_ns |
276 |
(ExpandedURI q<ddoct:>, 'ddoct:basePath', |
277 |
join '', '../' x ($path =~ tr#/#/#)); |
278 |
$pl_full_name =~ s/.*:://g; |
279 |
$section->perl_name ($pl_full_name); |
280 |
} |
281 |
|
282 |
$section->is_exception_interface (1) |
283 |
if $opt{source_resource}->is_type_uri |
284 |
(ExpandedURI q<ManakaiDOM:ExceptionIF>); |
285 |
|
286 |
append_description (source_resource => $opt{source_resource}, |
287 |
result_parent => $section); |
288 |
|
289 |
if ($opt{is_partial}) { |
290 |
$section->resource_is_partial (1); |
291 |
return; |
292 |
} |
293 |
|
294 |
## Inheritance |
295 |
append_inheritance (source_resource => $opt{source_resource}, |
296 |
result_parent => $section, |
297 |
class_uri => $class_uri); |
298 |
|
299 |
for my $memres (@{$opt{source_resource}->get_property_resource_list |
300 |
(ExpandedURI q<DIS:childResource>)}) { |
301 |
if ($memres->is_type_uri (ExpandedURI q<DISLang:Method>)) { |
302 |
append_method_documentation (source_resource => $memres, |
303 |
result_parent => $section, |
304 |
class_uri => $class_uri); |
305 |
} elsif ($memres->is_type_uri (ExpandedURI q<DISLang:Attribute>)) { |
306 |
append_attr_documentation (source_resource => $memres, |
307 |
result_parent => $section, |
308 |
class_uri => $class_uri); |
309 |
} elsif ($memres->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) { |
310 |
append_constgroup_documentation (source_resource => $memres, |
311 |
result_parent => $section, |
312 |
class_uri => $class_uri); |
313 |
} |
314 |
} |
315 |
} # append_interface_documentation |
316 |
|
317 |
sub append_class_documentation (%) { |
318 |
my %opt = @_; |
319 |
my $section = $opt{result_parent}->create_class |
320 |
(my $class_uri = $opt{source_resource}->uri); |
321 |
push @ClassInheritance, $class_uri; |
322 |
|
323 |
add_uri ($opt{source_resource} => $section); |
324 |
|
325 |
my $pl_full_name = $opt{source_resource}->pl_fully_qualified_name; |
326 |
if (defined $pl_full_name) { |
327 |
$section->perl_package_name ($pl_full_name); |
328 |
|
329 |
my $path = $opt{source_resource}->get_property_text |
330 |
(ExpandedURI q<dis:FileName>, $pl_full_name); |
331 |
$path =~ s#::#/#g; |
332 |
|
333 |
$section->resource_file_path_stem ($path); |
334 |
$section->set_attribute_ns |
335 |
(ExpandedURI q<ddoct:>, 'ddoct:basePath', '../' x ($path =~ tr#/#/#)); |
336 |
$pl_full_name =~ s/.*:://g; |
337 |
$section->perl_name ($pl_full_name); |
338 |
} |
339 |
|
340 |
append_description (source_resource => $opt{source_resource}, |
341 |
result_parent => $section); |
342 |
|
343 |
if ($opt{is_partial}) { |
344 |
$section->resource_is_partial (1); |
345 |
return; |
346 |
} |
347 |
|
348 |
my $has_const = 0; |
349 |
for my $memres (@{$opt{source_resource}->get_property_resource_list |
350 |
(ExpandedURI q<DIS:childResource>)}) { |
351 |
if ($memres->is_type_uri (ExpandedURI q<DISLang:Method>)) { |
352 |
append_method_documentation (source_resource => $memres, |
353 |
result_parent => $section, |
354 |
class_uri => $class_uri); |
355 |
} elsif ($memres->is_type_uri (ExpandedURI q<DISLang:Attribute>)) { |
356 |
append_attr_documentation (source_resource => $memres, |
357 |
result_parent => $section, |
358 |
class_uri => $class_uri); |
359 |
} elsif ($memres->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) { |
360 |
$has_const = 1; |
361 |
append_constgroup_documentation |
362 |
(source_resource => $memres, |
363 |
result_parent => $section, |
364 |
class_uri => $class_uri); |
365 |
} |
366 |
} |
367 |
|
368 |
## Inheritance |
369 |
append_inheritance (source_resource => $opt{source_resource}, |
370 |
result_parent => $section, |
371 |
append_implements => 1, |
372 |
class_uri => $class_uri, |
373 |
has_const => $has_const, |
374 |
is_class => 1); |
375 |
|
376 |
} # append_class_documentation |
377 |
|
378 |
sub append_method_documentation (%) { |
379 |
my %opt = @_; |
380 |
my $perl_name = $opt{source_resource}->pl_name; |
381 |
my $m; |
382 |
if (defined $perl_name) { |
383 |
$m = $opt{result_parent}->create_method ($perl_name); |
384 |
$ClassMembers{$opt{class_uri}}->{$perl_name} |
385 |
= { |
386 |
resource => $opt{source_resource}, |
387 |
type => 'method', |
388 |
}; |
389 |
|
390 |
} else { ## Anonymous |
391 |
## TODO |
392 |
return; |
393 |
} |
394 |
|
395 |
add_uri ($opt{source_resource} => $m); |
396 |
|
397 |
append_description (source_resource => $opt{source_resource}, |
398 |
result_parent => $m, |
399 |
method_resource => $opt{source_resource}); |
400 |
|
401 |
my $ret = $opt{source_resource}->get_child_resource_by_type |
402 |
(ExpandedURI q<DISLang:MethodReturn>); |
403 |
if ($ret) { |
404 |
my $r = $m->dis_return; |
405 |
|
406 |
try { |
407 |
$r->resource_data_type (my $u = $ret->dis_data_type_resource->uri); |
408 |
$ReferredResource{$u} ||= 1; |
409 |
$r->resource_actual_data_type |
410 |
($u = $ret->dis_actual_data_type_resource->uri); |
411 |
$ReferredResource{$u} ||= 1; |
412 |
|
413 |
## TODO: Exceptions |
414 |
} catch Message::Util::DIS::ManakaiDISException with { |
415 |
|
416 |
}; |
417 |
|
418 |
append_description (source_resource => $ret, |
419 |
result_parent => $r, |
420 |
has_case => 1, |
421 |
method_resource => $opt{source_resource}); |
422 |
|
423 |
append_raises (source_resource => $ret, |
424 |
result_parent => $r, |
425 |
method_resource => $opt{source_resource}); |
426 |
} |
427 |
|
428 |
for my $cr (@{$opt{source_resource}->get_property_resource_list |
429 |
(ExpandedURI q<DIS:childResource>)}) { |
430 |
if ($cr->is_type_uri (ExpandedURI q<DISLang:MethodParameter>)) { |
431 |
append_param_documentation (source_resource => $cr, |
432 |
result_parent => $m, |
433 |
method_resource => $opt{source_resource}); |
434 |
} |
435 |
} |
436 |
|
437 |
$m->resource_access ('private') |
438 |
if $opt{source_resource}->get_property_boolean |
439 |
(ExpandedURI q<ManakaiDOM:isForInternal>, 0); |
440 |
} # append_method_documentation |
441 |
|
442 |
sub append_attr_documentation (%) { |
443 |
my %opt = @_; |
444 |
my $perl_name = $opt{source_resource}->pl_name; |
445 |
my $m; |
446 |
if (defined $perl_name) { |
447 |
$m = $opt{result_parent}->create_attribute ($perl_name); |
448 |
$ClassMembers{$opt{class_uri}}->{$perl_name} |
449 |
= { |
450 |
resource => $opt{source_resource}, |
451 |
type => 'attr', |
452 |
}; |
453 |
|
454 |
} else { ## Anonymous |
455 |
## TODO |
456 |
return; |
457 |
} |
458 |
|
459 |
add_uri ($opt{source_resource} => $m); |
460 |
|
461 |
append_description (source_resource => $opt{source_resource}, |
462 |
result_parent => $m, |
463 |
has_case => 1); |
464 |
|
465 |
my $ret = $opt{source_resource}->get_child_resource_by_type |
466 |
(ExpandedURI q<DISLang:AttributeGet>); |
467 |
if ($ret) { |
468 |
my $r = $m->dis_get; |
469 |
|
470 |
$r->resource_data_type (my $u = $ret->dis_data_type_resource->uri); |
471 |
$ReferredResource{$u} ||= 1; |
472 |
$r->resource_actual_data_type |
473 |
($u = $ret->dis_actual_data_type_resource->uri); |
474 |
$ReferredResource{$u} ||= 1; |
475 |
|
476 |
append_description (source_resource => $ret, |
477 |
result_parent => $r, |
478 |
has_case => 1); |
479 |
|
480 |
append_raises (source_resource => $ret, |
481 |
result_parent => $r); |
482 |
} |
483 |
|
484 |
my $set = $opt{source_resource}->get_child_resource_by_type |
485 |
(ExpandedURI q<DISLang:AttributeSet>); |
486 |
if ($set) { |
487 |
my $r = $m->dis_set; |
488 |
|
489 |
$r->resource_data_type (my $u = $set->dis_data_type_resource->uri); |
490 |
$ReferredResource{$u} ||= 1; |
491 |
$r->resource_actual_data_type ($set->dis_actual_data_type_resource->uri); |
492 |
$ReferredResource{$u} ||= 1; |
493 |
|
494 |
append_description (source_resource => $set, |
495 |
result_parent => $r, |
496 |
has_case => 1); |
497 |
|
498 |
append_raises (source_resource => $set, |
499 |
result_parent => $r); |
500 |
} else { |
501 |
$m->is_read_only_attribute (1); |
502 |
} |
503 |
|
504 |
$m->resource_access ('private') |
505 |
if $opt{source_resource}->get_property_boolean |
506 |
(ExpandedURI q<ManakaiDOM:isForInternal>, 0); |
507 |
} # append_attr_documentation |
508 |
|
509 |
sub append_constgroup_documentation (%) { |
510 |
my %opt = @_; |
511 |
my $perl_name = $opt{source_resource}->pl_name; |
512 |
my $m = $opt{result_parent}->create_const_group ($perl_name); |
513 |
$ClassMembers{$opt{class_uri}}->{$perl_name} |
514 |
= { |
515 |
resource => $opt{source_resource}, |
516 |
type => 'const-group', |
517 |
}; |
518 |
|
519 |
add_uri ($opt{source_resource} => $m); |
520 |
|
521 |
append_description (source_resource => $opt{source_resource}, |
522 |
result_parent => $m); |
523 |
|
524 |
$m->resource_data_type |
525 |
(my $u = $opt{source_resource}->dis_data_type_resource->uri); |
526 |
$ReferredResource{$u} ||= 1; |
527 |
$m->resource_actual_data_type |
528 |
($u = $opt{source_resource}->dis_actual_data_type_resource->uri); |
529 |
$ReferredResource{$u} ||= 1; |
530 |
|
531 |
append_subclassof (source_resource => $opt{source_resource}, |
532 |
result_parent => $m); |
533 |
|
534 |
for my $cr (@{$opt{source_resource}->get_property_resource_list |
535 |
(ExpandedURI q<DIS:childResource>)}) { |
536 |
if ($cr->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) { |
537 |
append_const_documentation (source_resource => $cr, |
538 |
result_parent => $m); |
539 |
} |
540 |
} |
541 |
} # append_constgroup_documentation |
542 |
|
543 |
sub append_const_documentation (%) { |
544 |
my %opt = @_; |
545 |
my $perl_name = $opt{source_resource}->pl_name; |
546 |
my $m = $opt{result_parent}->create_const ($perl_name); |
547 |
|
548 |
add_uri ($opt{source_resource} => $m); |
549 |
|
550 |
append_description (source_resource => $opt{source_resource}, |
551 |
result_parent => $m); |
552 |
|
553 |
$m->resource_data_type |
554 |
(my $u = $opt{source_resource}->dis_data_type_resource->uri); |
555 |
$ReferredResource{$u} ||= 1; |
556 |
$m->resource_actual_data_type |
557 |
($u = $opt{source_resource}->dis_actual_data_type_resource->uri); |
558 |
$ReferredResource{$u} ||= 1; |
559 |
|
560 |
my $value = $opt{source_resource}->pl_code_fragment; |
561 |
if ($value) { |
562 |
$m->create_value->text_content ($value->stringify); |
563 |
} |
564 |
|
565 |
for my $cr (@{$opt{source_resource}->get_property_resource_list |
566 |
(ExpandedURI q<DIS:childResource>)}) { |
567 |
if ($cr->is_type_uri (ExpandedURI q<ManakaiDOM:ExceptionOrWarningSubType>)) { |
568 |
append_xsubtype_documentation (source_resource => $cr, |
569 |
result_parent => $m); |
570 |
} |
571 |
} |
572 |
## TODO: xparam |
573 |
} # append_const_documentation |
574 |
|
575 |
sub append_xsubtype_documentation (%) { |
576 |
my %opt = @_; |
577 |
my $m = $opt{result_parent}->create_exception_sub_code |
578 |
($opt{source_resource}->uri); |
579 |
add_uri ($opt{source_resource} => $m); |
580 |
|
581 |
append_description (source_resource => $opt{source_resource}, |
582 |
result_parent => $m); |
583 |
|
584 |
## TODO: xparam |
585 |
} # append_xsubtype_documentation |
586 |
|
587 |
sub append_param_documentation (%) { |
588 |
my %opt = @_; |
589 |
|
590 |
my $is_named_param = $opt{source_resource}->get_property_boolean |
591 |
(ExpandedURI q<DISPerl:isNamedParameter>, 0); |
592 |
|
593 |
my $perl_name = $is_named_param |
594 |
? $opt{source_resource}->pl_name |
595 |
: $opt{source_resource}->pl_variable_name; |
596 |
|
597 |
my $p = $opt{result_parent}->create_parameter ($perl_name, $is_named_param); |
598 |
|
599 |
add_uri ($opt{source_resource} => $p); |
600 |
|
601 |
$p->is_nullable_parameter ($opt{source_resource}->pl_is_nullable); |
602 |
$p->resource_data_type |
603 |
(my $u = $opt{source_resource}->dis_data_type_resource->uri); |
604 |
$ReferredResource{$u} ||= 1; |
605 |
$p->resource_actual_data_type |
606 |
($u = $opt{source_resource}->dis_actual_data_type_resource->uri); |
607 |
$ReferredResource{$u} ||= 1; |
608 |
|
609 |
append_description (source_resource => $opt{source_resource}, |
610 |
result_parent => $p, |
611 |
has_case => 1, |
612 |
method_resource => $opt{method_resource}); |
613 |
} # append_param_documentation |
614 |
|
615 |
sub append_description (%) { |
616 |
my %opt = @_; |
617 |
|
618 |
my $od = $opt{result_parent}->owner_document; |
619 |
my $resd = $opt{source_resource}->get_feature (ExpandedURI q<DIS:Doc>, '2.0'); |
620 |
my $doc = transform_disdoc_tree |
621 |
($resd->get_description |
622 |
($od, undef, |
623 |
$Opt{with_impl_note}, |
624 |
parent_element_arg => $opt{source_element}), |
625 |
method_resource => $opt{method_resource}); |
626 |
$opt{result_parent}->create_description->append_child ($doc); |
627 |
## TODO: Negotiation |
628 |
|
629 |
my $fn = $resd->get_full_name ($od); |
630 |
if ($fn) { |
631 |
$opt{result_parent}->create_full_name |
632 |
->append_child (transform_disdoc_tree |
633 |
($fn, |
634 |
method_resource => $opt{method_resource})); |
635 |
} |
636 |
|
637 |
if ($opt{has_case}) { |
638 |
for my $caser (@{$opt{source_resource}->get_property_resource_list |
639 |
(ExpandedURI q<DIS:childResource>)}) { |
640 |
if ($caser->is_type_uri (ExpandedURI q<ManakaiDOM:InCase>)) { |
641 |
my $case = $opt{result_parent}->append_case; |
642 |
my $cased = $caser->get_feature (ExpandedURI q<DIS:Doc>, '2.0'); |
643 |
my $label = $cased->get_label ($od); |
644 |
if ($label) { |
645 |
$case->create_label->append_child |
646 |
(transform_disdoc_tree ($label, |
647 |
method_resource => $opt{method_resource})); |
648 |
} |
649 |
my $value = $caser->pl_code_fragment; |
650 |
if ($value) { |
651 |
$case->create_value->text_content ($value->stringify); |
652 |
} |
653 |
$case->resource_data_type |
654 |
(my $u = $caser->dis_data_type_resource->uri); |
655 |
$ReferredResource{$u} ||= 1; |
656 |
$case->resource_actual_data_type |
657 |
($u = $caser->dis_actual_data_type_resource->uri); |
658 |
$ReferredResource{$u} ||= 1; |
659 |
|
660 |
append_description (source_resource => $caser, |
661 |
result_parent => $case, |
662 |
method_resource => $opt{method_resource}); |
663 |
} |
664 |
} |
665 |
} |
666 |
} # append_description |
667 |
|
668 |
sub transform_disdoc_tree ($;%) { |
669 |
my ($el, %opt) = @_; |
670 |
my @el = ($el); |
671 |
EL: while (defined (my $el = shift @el)) { |
672 |
if ($el->node_type == $el->ELEMENT_NODE and |
673 |
defined $el->namespace_uri) { |
674 |
my $mmParsed = $el->get_attribute_ns (ExpandedURI q<ddel:>, 'mmParsed'); |
675 |
if ($mmParsed) { |
676 |
my $lextype = $el->get_attribute_ns (ExpandedURI q<ddel:>, 'lexType'); |
677 |
if ($lextype eq ExpandedURI q<dis:TFQNames>) { |
678 |
my $uri = dd_get_tfqnames_uri ($el); |
679 |
if (defined $uri) { |
680 |
$ReferredResource{$uri} ||= 1; |
681 |
next EL; |
682 |
} |
683 |
} elsif ($lextype eq ExpandedURI q<dis:TypeQName> or |
684 |
$lextype eq ExpandedURI q<DISCore:NCNameOrQName>) { |
685 |
my $uri = dd_get_qname_uri ($el); |
686 |
if (defined $uri) { |
687 |
$ReferredResource{$uri} ||= 1; |
688 |
next EL; |
689 |
} |
690 |
} elsif ($lextype eq ExpandedURI q<DISPerl:MemRef> or |
691 |
$lextype eq ExpandedURI q<DOMMain:XCodeRef>) { |
692 |
my @nm = @{$el->get_elements_by_tag_name_ns |
693 |
(ExpandedURI q<ddel:>, 'name')}; |
694 |
if (@nm == 1) { |
695 |
my $uri = dd_get_tfqnames_uri ($nm[0]); |
696 |
if (defined $uri) { |
697 |
$el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri); |
698 |
$ReferredResource{$uri} ||= 1; |
699 |
next EL; |
700 |
} |
701 |
} elsif (@nm == 3) { |
702 |
my $uri = dd_get_tfqnames_uri ($nm[2]); |
703 |
if (defined $uri) { |
704 |
$el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri); |
705 |
$ReferredResource{$uri} ||= 1; |
706 |
next EL; |
707 |
} |
708 |
} elsif (@nm == 2) { |
709 |
my $uri = dd_get_tfqnames_uri ($nm[0]); |
710 |
if (not defined $uri) { |
711 |
# |
712 |
} elsif ($nm[1]->get_elements_by_tag_name_ns |
713 |
(ExpandedURI q<ddel:>, 'prefix')->[0]) { |
714 |
#my $luri = dd_get_qname_uri ($nm[1]); |
715 |
## QName: Currently not used |
716 |
} else { |
717 |
my $lnel = $nm[1]->get_elements_by_tag_name_ns |
718 |
(ExpandedURI q<ddel:>, 'localName')->[0]; |
719 |
my $lname = $lnel ? $lnel->text_content : ''; |
720 |
my $res; |
721 |
if ($lextype eq ExpandedURI q<DOMMain:XCodeRef> or |
722 |
{ |
723 |
ExpandedURI q<ddel:C> => 1, |
724 |
ExpandedURI q<ddel:X> => 1, |
725 |
}->{$el->namespace_uri . $el->local_name}) { |
726 |
## NOTE: $db |
727 |
$res = $db->get_resource ($uri) |
728 |
->get_const_resource_by_name ($lname); |
729 |
} else { |
730 |
## NOTE: $db |
731 |
$res = $db->get_resource ($uri) |
732 |
->get_child_resource_by_name_and_type |
733 |
($lname, ExpandedURI q<DISLang:AnyMethod>); |
734 |
} |
735 |
if ($res) { |
736 |
$el->set_attribute_ns |
737 |
(ExpandedURI q<dump:>, 'dump:uri', $res->uri); |
738 |
$ReferredResource{$res->uri} ||= 1; |
739 |
} |
740 |
next EL; |
741 |
} |
742 |
} |
743 |
} # lextype |
744 |
} # mmParsed |
745 |
elsif ($opt{method_resource} and |
746 |
$el->namespace_uri eq ExpandedURI q<ddel:> and |
747 |
$el->local_name eq 'P') { |
748 |
my $res = $opt{method_resource} |
749 |
->get_child_resource_by_name_and_type |
750 |
($el->text_content, ExpandedURI q<DISLang:MethodParameter>); |
751 |
if ($res) { |
752 |
$el->set_attribute_ns |
753 |
(ExpandedURI q<dump:>, 'dump:uri', $res->uri); |
754 |
$ReferredResource{$res->uri} ||= 1; |
755 |
} |
756 |
next EL; |
757 |
} |
758 |
push @el, @{$el->child_nodes}; |
759 |
} elsif ($el->node_type == $el->DOCUMENT_FRAGMENT_NODE or |
760 |
$el->node_type == $el->DOCUMENT_NODE) { |
761 |
push @el, @{$el->child_nodes}; |
762 |
} |
763 |
} # EL |
764 |
$el; |
765 |
} # transform_disdoc_tree |
766 |
|
767 |
sub dd_get_tfqnames_uri ($;%) { |
768 |
my ($el, %opt) = @_; |
769 |
return '' unless $el; |
770 |
my $turi = dd_get_qname_uri ($el->get_elements_by_tag_name_ns |
771 |
(ExpandedURI q<ddel:>, 'nameQName')->[0]); |
772 |
my $furi = dd_get_qname_uri ($el->get_elements_by_tag_name_ns |
773 |
(ExpandedURI q<ddel:>, 'forQName')->[0]); |
774 |
return undef if not defined $turi or not defined $furi; |
775 |
my $uri = tfuris2uri ($turi, $furi); |
776 |
$el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:uri', $uri); |
777 |
$uri; |
778 |
} # dd_get_tfqnames_uri |
779 |
|
780 |
sub dd_get_qname_uri ($;%) { |
781 |
my ($el, %opt) = @_; |
782 |
return undef unless $el; |
783 |
my $plel = $el->get_elements_by_tag_name_ns |
784 |
(ExpandedURI q<ddel:>, 'prefix')->[0]; |
785 |
my $lnel = $el->get_elements_by_tag_name_ns |
786 |
(ExpandedURI q<ddel:>, 'localName')->[0]; |
787 |
my $nsuri = ($plel ? $plel : $el)->lookup_namespace_uri |
788 |
($plel ? $plel->text_content : undef); |
789 |
$nsuri = '' unless defined $nsuri; |
790 |
if ($plel and $nsuri eq '') { |
791 |
$plel->remove_attribute_ns |
792 |
(ExpandedURI q<xmlns:>, $plel->text_content); |
793 |
$el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:namespaceURI', $nsuri); |
794 |
return undef; |
795 |
} else { |
796 |
$el->set_attribute_ns (ExpandedURI q<dump:>, 'dump:namespaceURI', $nsuri); |
797 |
} |
798 |
if ($lnel) { |
799 |
$nsuri . $lnel->text_content; |
800 |
} else { |
801 |
$el->get_attribute_ns (ExpandedURI q<ddel:>, 'defaultURI'); |
802 |
} |
803 |
} # dd_get_qname_uri |
804 |
|
805 |
sub tfuris2uri ($$) { |
806 |
my ($turi, $furi) = @_; |
807 |
my $uri; |
808 |
if ($furi eq ExpandedURI q<ManakaiDOM:all>) { |
809 |
$uri = $turi; |
810 |
} else { |
811 |
my $__turi = $turi; |
812 |
my $__furi = $furi; |
813 |
for my $__uri ($__turi, $__furi) { |
814 |
$__uri =~ s{([^0-9A-Za-z:;?=_./-])}{sprintf '%%%02X', ord $1}ge; |
815 |
} |
816 |
$uri = qq<data:,200411tf#xmlns(t=data:,200411tf%23)>. |
817 |
qq<t:tf($__turi,$__furi)>; |
818 |
} |
819 |
$uri; |
820 |
} # tfuris2uri |
821 |
|
822 |
sub append_inheritance (%) { |
823 |
my %opt = @_; |
824 |
if (($opt{depth} ||= 0) == 100) { |
825 |
warn "<".$opt{source_resource}->uri.">: Loop in inheritance"; |
826 |
return; |
827 |
} |
828 |
|
829 |
my $has_isa = 0; |
830 |
|
831 |
for my $isa (@{$opt{source_resource}->get_property_resource_list |
832 |
(ExpandedURI q<dis:ISA>, |
833 |
default_media_type => ExpandedURI q<dis:TFQNames>)}) { |
834 |
$has_isa = 1; |
835 |
append_inheritance |
836 |
(source_resource => $isa, |
837 |
result_parent => $opt{result_parent}->append_new_extends ($isa->uri), |
838 |
depth => $opt{depth} + 1, |
839 |
is_class => $opt{is_class}); |
840 |
$ReferredResource{$isa->uri} ||= 1; |
841 |
if ($opt{class_uri}) { |
842 |
unshift @ClassInheritance, $isa->uri; |
843 |
push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri; |
844 |
} |
845 |
} |
846 |
|
847 |
if ($opt{source_resource}->is_defined) { |
848 |
for my $isa_pack (@{$opt{source_resource}->pl_additional_isa_packages}) { |
849 |
my $isa; |
850 |
if ($isa_pack eq 'Message::Util::Error') { |
851 |
## NOTE: $db |
852 |
$isa = $db->get_resource (ExpandedURI q<ecore:MUError>, |
853 |
for_arg => ExpandedURI q<ManakaiDOM:Perl>); |
854 |
} elsif ($isa_pack eq 'Tie::Array') { |
855 |
## NOTE: $db |
856 |
$isa = $db->get_resource (ExpandedURI q<DISPerl:TieArray>); |
857 |
} elsif ($isa_pack eq 'Error') { |
858 |
## NOTE: $db |
859 |
$isa = $db->get_resource (ExpandedURI q<ecore:Error>, |
860 |
for_arg => ExpandedURI q<ManakaiDOM:Perl>); |
861 |
} else { |
862 |
## TODO: What to do? |
863 |
} |
864 |
if ($isa) { |
865 |
$has_isa = 1; |
866 |
append_inheritance |
867 |
(source_resource => $isa, |
868 |
result_parent => $opt{result_parent}->append_new_extends ($isa->uri), |
869 |
depth => $opt{depth} + 1, |
870 |
is_class => $opt{is_class}); |
871 |
$ReferredResource{$isa->uri} ||= 1; |
872 |
if ($opt{class_uri}) { |
873 |
unshift @ClassInheritance, $isa->uri; |
874 |
push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri; |
875 |
} |
876 |
} |
877 |
}} # AppISA |
878 |
|
879 |
if ($opt{has_const}) { |
880 |
## NOTE: $db |
881 |
my $isa = $db->get_resource (ExpandedURI q<DISPerl:Exporter>); |
882 |
append_inheritance |
883 |
(source_resource => $isa, |
884 |
result_parent => $opt{result_parent}->append_new_extends ($isa->uri), |
885 |
depth => $opt{depth} + 1, |
886 |
is_class => $opt{is_class}); |
887 |
$ReferredResource{$isa->uri} ||= 1; |
888 |
if ($opt{class_uri}) { |
889 |
unshift @ClassInheritance, $isa->uri; |
890 |
push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri; |
891 |
} |
892 |
} |
893 |
|
894 |
if (not $has_isa and $opt{is_class} and |
895 |
$opt{source_resource}->uri ne ExpandedURI q<DISPerl:UNIVERSAL>) { |
896 |
## NOTE: $db |
897 |
my $isa = $db->get_resource (ExpandedURI q<DISPerl:UNIVERSAL>); |
898 |
append_inheritance |
899 |
(source_resource => $isa, |
900 |
result_parent => $opt{result_parent}->append_new_extends ($isa->uri), |
901 |
depth => $opt{depth} + 1, |
902 |
is_class => $opt{is_class}); |
903 |
$ReferredResource{$isa->uri} ||= 1; |
904 |
if ($opt{class_uri}) { |
905 |
unshift @ClassInheritance, $isa->uri; |
906 |
push @{$ClassInheritance{$opt{class_uri}} ||= []}, $isa->uri; |
907 |
} |
908 |
} |
909 |
|
910 |
if ($opt{append_implements}) { |
911 |
## NOTE: $db |
912 |
my $u = $db->get_resource (ExpandedURI q<DISPerl:UNIVERSALInterface>); |
913 |
for my $impl (@{$opt{source_resource}->get_property_resource_list |
914 |
(ExpandedURI q<dis:Implement>, |
915 |
default_media_type => ExpandedURI q<dis:TFQNames>, |
916 |
isa_recursive => 1)}, $u) { |
917 |
append_inheritance |
918 |
(source_resource => $impl, |
919 |
result_parent => $opt{result_parent}->append_new_implements |
920 |
($impl->uri), |
921 |
depth => $opt{depth}); |
922 |
$ReferredResource{$impl->uri} ||= 1; |
923 |
$ClassImplements{$opt{class_uri}}->{$impl->uri} = 1 |
924 |
if $opt{class_uri}; |
925 |
} |
926 |
} |
927 |
} # append_inheritance |
928 |
|
929 |
sub append_subclassof (%) { |
930 |
my %opt = @_; |
931 |
|
932 |
## NOTE: This subroutine directly access to internal structure |
933 |
## of ManakaiDISResourceDefinition |
934 |
|
935 |
my $a; |
936 |
$a = sub ($$) { |
937 |
my ($gdb, $s) = @_; |
938 |
my %s = keys %$s; |
939 |
while (my $i = [keys %s]->[0]) { |
940 |
## Removes itself |
941 |
delete $s->{$i}; |
942 |
#warn $i; |
943 |
|
944 |
my $ires = $gdb->get_resource ($i); |
945 |
for my $j (keys %$s) { |
946 |
next if $i eq $j; |
947 |
if ($ires->{subOf}->{$j}) { |
948 |
$s->{$i}->{$j} = $s->{$j}; |
949 |
delete $s->{$j}; |
950 |
delete $s{$j}; |
951 |
} |
952 |
} |
953 |
|
954 |
delete $s{$i}; |
955 |
} # %s |
956 |
|
957 |
for my $i (keys %$s) { |
958 |
$a->($s->{$i}) if keys %{$s->{$i}}; |
959 |
} |
960 |
}; |
961 |
|
962 |
my $b; |
963 |
$b = sub ($$) { |
964 |
my ($s, $p) = @_; |
965 |
for my $i (keys %$s) { |
966 |
my $el = $p->append_new_sub_class_of ($i); |
967 |
$b->($s->{$i}, $el) if keys %{$s->{$i}}; |
968 |
} |
969 |
}; |
970 |
|
971 |
|
972 |
my $sub = {$opt{source_resource}->uri => |
973 |
{map {$_ => {}} keys %{$opt{source_resource}->{subOf}}}}; |
974 |
## NOTE: $db |
975 |
$a->($db, $sub); |
976 |
$b->($sub, $opt{result_parent}); |
977 |
} # append_subclassof |
978 |
|
979 |
sub add_uri ($$;%) { |
980 |
my ($res, $el, %opt) = @_; |
981 |
my $canon_uri = $res->uri; |
982 |
for my $uri (@{$res->uris}) { |
983 |
$el->add_uri ($uri, $canon_uri eq $uri ? 0 : 1); |
984 |
$ReferredResource{$uri} = -1; |
985 |
} |
986 |
|
987 |
my $nsuri = $res->namespace_uri; |
988 |
$el->resource_namespace_uri ($nsuri) if defined $nsuri; |
989 |
my $lname = $res->local_name; |
990 |
$el->resource_local_name ($lname) if defined $lname; |
991 |
} # add_uri |
992 |
|
993 |
sub append_raises (%) { |
994 |
my %opt = @_; |
995 |
my $parent = $opt{source_resource}->source_element; |
996 |
return unless $parent; |
997 |
|
998 |
for my $el (@{$parent->dis_child_elements |
999 |
(for_arg => $opt{source_resource}->for_uri, |
1000 |
forp_arg => $opt{source_resource}->forp_uri)}) { |
1001 |
if ($el->expanded_uri eq ExpandedURI q<ManakaiDOM:raises>) { |
1002 |
## NOTE: $db is used |
1003 |
my ($a, $b, $c) = @{$db->xcref_to_resource |
1004 |
($el->value, $el, |
1005 |
for_arg => $opt{source_resource}->for_uri)}; |
1006 |
|
1007 |
my $rel = $opt{result_parent}->create_raises |
1008 |
($a->uri, $b ? $b->uri : undef, $c ? $c->uri : undef); |
1009 |
|
1010 |
append_description (source_resource => $opt{source_resource}, |
1011 |
source_element => $el, |
1012 |
result_parent => $rel, |
1013 |
method_resource => $opt{method_resource}); |
1014 |
} |
1015 |
} |
1016 |
} # append_raises |
1017 |
|
1018 |
|
1019 |
my $doc = $impl->create_disdump_document; |
1020 |
|
1021 |
my $body = $doc->document_element; |
1022 |
|
1023 |
|
1024 |
## -- Outputs requested modules |
1025 |
|
1026 |
for my $mod_uri (keys %{$Opt{module_uri}}) { |
1027 |
my $mod_for = $Opt{For}; |
1028 |
my $mod = $db->get_module ($mod_uri, for_arg => $mod_for); |
1029 |
unless ($mod_for) { |
1030 |
my $el = $mod->source_element; |
1031 |
if ($el) { |
1032 |
$mod_for = $el->default_for_uri; |
1033 |
$mod = $db->get_module ($mod_uri, for_arg => $mod_for); |
1034 |
} |
1035 |
} |
1036 |
unless ($mod->is_defined) { |
1037 |
die qq<$0: Module <$mod_uri> for <$mod_for> is not defined>; |
1038 |
} |
1039 |
|
1040 |
status_msg qq<Module <$mod_uri> for <$mod_for>...>; |
1041 |
|
1042 |
append_module_documentation |
1043 |
(result_parent => $body, |
1044 |
source_resource => $mod); |
1045 |
|
1046 |
status_msg qq<done>; |
1047 |
} # mod_uri |
1048 |
|
1049 |
## -- Outputs referenced resources in external modules |
1050 |
|
1051 |
status_msg q<Other modules...>; |
1052 |
|
1053 |
while (my @ruri = grep {$ReferredResource{$_} > 0} keys %ReferredResource) { |
1054 |
U: while (defined (my $uri = shift @ruri)) { |
1055 |
next U if $ReferredResource{$uri} < 0; ## Already done |
1056 |
status_msg_ q<*>; |
1057 |
my $res = $db->get_resource ($uri); |
1058 |
unless ($res->is_defined) { |
1059 |
$res = $db->get_module ($uri); |
1060 |
unless ($res->is_defined) { |
1061 |
$ReferredResource{$uri} = -1; |
1062 |
next U; |
1063 |
} |
1064 |
append_module_documentation |
1065 |
(result_parent => $body, |
1066 |
source_resource => $res, |
1067 |
is_partial => 1); |
1068 |
} elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:Class>)) { |
1069 |
my $mod = $res->owner_module; |
1070 |
unless ($ReferredResource{$mod->uri} < 0) { |
1071 |
unshift @ruri, $uri; |
1072 |
unshift @ruri, $mod->uri; |
1073 |
next U; |
1074 |
} |
1075 |
append_class_documentation |
1076 |
(result_parent => $body->create_module ($mod->uri), |
1077 |
source_resource => $res, |
1078 |
is_partial => 1); |
1079 |
} elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) { |
1080 |
my $mod = $res->owner_module; |
1081 |
unless ($mod->is_defined) { |
1082 |
$ReferredResource{$uri} = -1; |
1083 |
next U; |
1084 |
} elsif (not ($ReferredResource{$mod->uri} < 0)) { |
1085 |
unshift @ruri, $uri; |
1086 |
unshift @ruri, $mod->uri; |
1087 |
next U; |
1088 |
} |
1089 |
append_interface_documentation |
1090 |
(result_parent => $body->create_module ($mod->uri), |
1091 |
source_resource => $res, |
1092 |
is_partial => 1); |
1093 |
} elsif ($res->is_type_uri (ExpandedURI q<DISCore:AbstractDataType>)) { |
1094 |
my $mod = $res->owner_module; |
1095 |
unless ($mod->is_defined) { |
1096 |
$ReferredResource{$uri} = -1; |
1097 |
next U; |
1098 |
} elsif (not ($ReferredResource{$mod->uri} < 0)) { |
1099 |
unshift @ruri, $uri; |
1100 |
unshift @ruri, $mod->uri; |
1101 |
next U; |
1102 |
} |
1103 |
append_datatype_documentation |
1104 |
(result_parent => $body->create_module ($mod->uri), |
1105 |
source_resource => $res); |
1106 |
} elsif ($res->is_type_uri (ExpandedURI q<DISLang:AnyMethod>) or |
1107 |
$res->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) { |
1108 |
my $cls = $res->get_property_resource |
1109 |
(ExpandedURI q<dis2pm:parentResource>); |
1110 |
if (not ($ReferredResource{$cls->uri} < 0) and |
1111 |
($cls->is_type_uri (ExpandedURI q<ManakaiDOM:Class>) or |
1112 |
$cls->is_type_uri (ExpandedURI q<ManakaiDOM:IF>))) { |
1113 |
unshift @ruri, $uri; |
1114 |
unshift @ruri, $cls->uri; |
1115 |
next U; |
1116 |
} |
1117 |
my $model = $body->create_module ($cls->owner_module->uri); |
1118 |
my $clsel = $cls->is_type_uri (ExpandedURI q<ManakaiDOM:Class>) |
1119 |
? $model->create_class ($cls->uri) |
1120 |
: $model->create_interface ($cls->uri); |
1121 |
if ($res->is_type_uri (ExpandedURI q<DISLang:Method>)) { |
1122 |
append_method_documentation |
1123 |
(result_parent => $clsel, |
1124 |
source_resource => $res); |
1125 |
} elsif ($res->is_type_uri (ExpandedURI q<DISLang:Attribute>)) { |
1126 |
append_attr_documentation |
1127 |
(result_parent => $clsel, |
1128 |
source_resource => $res); |
1129 |
} elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) { |
1130 |
append_constgroup_documentation |
1131 |
(result_parent => $clsel, |
1132 |
source_resource => $res); |
1133 |
} |
1134 |
} elsif ($res->is_type_uri (ExpandedURI q<DISLang:MethodParameter>)) { |
1135 |
my $m = $res->get_property_resource |
1136 |
(ExpandedURI q<dis2pm:parentResource>); |
1137 |
if (not ($ReferredResource{$m->uri} < 0) and |
1138 |
$m->is_type_uri (ExpandedURI q<DISLang:Method>)) { |
1139 |
unshift @ruri, $m->uri; |
1140 |
$ReferredResource{$res->uri} = -1; |
1141 |
next U; |
1142 |
} |
1143 |
} elsif ($res->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) { |
1144 |
my $m = $res->get_property_resource |
1145 |
(ExpandedURI q<dis2pm:parentResource>); |
1146 |
if (not ($ReferredResource{$m->uri} < 0) and |
1147 |
$m->is_type_uri (ExpandedURI q<ManakaiDOM:ConstGroup>)) { |
1148 |
unshift @ruri, $m->uri; |
1149 |
$ReferredResource{$res->uri} = -1; |
1150 |
next U; |
1151 |
} |
1152 |
} elsif ($res->is_type_uri |
1153 |
(ExpandedURI q<ManakaiDOM:ExceptionOrWarningSubType>)) { |
1154 |
my $m = $res->get_property_resource |
1155 |
(ExpandedURI q<dis2pm:parentResource>); |
1156 |
if (not ($ReferredResource{$m->uri} < 0) and |
1157 |
$m->is_type_uri (ExpandedURI q<ManakaiDOM:Const>)) { |
1158 |
unshift @ruri, $m->uri; |
1159 |
$ReferredResource{$res->uri} = -1; |
1160 |
next U; |
1161 |
} |
1162 |
} else { ## Unsupported type |
1163 |
$ReferredResource{$uri} = -1; |
1164 |
} |
1165 |
} # U |
1166 |
} |
1167 |
|
1168 |
status_msg q<done>; |
1169 |
|
1170 |
## -- Inheriting methods information |
1171 |
|
1172 |
{ |
1173 |
verbose_msg_ q<Adding inheritance information...>; |
1174 |
my %class_done; |
1175 |
for my $class_uri (@ClassInheritance) { |
1176 |
next if $class_done{$class_uri}; |
1177 |
$class_done{$class_uri}; |
1178 |
for my $sclass_uri (@{$ClassInheritance{$class_uri}}) { |
1179 |
for my $scm_name (keys %{$ClassMembers{$sclass_uri}}) { |
1180 |
if ($ClassMembers{$class_uri}->{$scm_name}) { |
1181 |
$ClassMembers{$class_uri}->{$scm_name}->{overrides} |
1182 |
->{$ClassMembers{$sclass_uri}->{$scm_name}->{resource}->uri} = 1; |
1183 |
} else { |
1184 |
$ClassMembers{$class_uri}->{$scm_name} |
1185 |
= { |
1186 |
%{$ClassMembers{$sclass_uri}->{$scm_name}}, |
1187 |
is_inherited => 1, |
1188 |
}; |
1189 |
} |
1190 |
} |
1191 |
} # superclasses |
1192 |
} # classes |
1193 |
|
1194 |
for my $class_uri (keys %ClassImplements) { |
1195 |
for my $if_uri (keys %{$ClassImplements{$class_uri}||{}}) { |
1196 |
for my $mem_name (keys %{$ClassMembers{$if_uri}}) { |
1197 |
unless ($ClassMembers{$class_uri}->{$mem_name}) { |
1198 |
## Not defined - error |
1199 |
$ClassMembers{$class_uri}->{$mem_name} |
1200 |
= { |
1201 |
%{$ClassMembers{$if_uri}->{$mem_name}}, |
1202 |
is_inherited => 1, |
1203 |
}; |
1204 |
} |
1205 |
$ClassMembers{$class_uri}->{$mem_name}->{implements} |
1206 |
->{$ClassMembers{$if_uri}->{$mem_name}->{resource}->uri} = 1; |
1207 |
} |
1208 |
} # interfaces |
1209 |
} # classes |
1210 |
|
1211 |
for my $class_uri (keys %ClassMembers) { |
1212 |
my $cls_res = $db->get_resource ($class_uri); |
1213 |
next unless $cls_res->is_defined; |
1214 |
verbose_msg_ q<.>; |
1215 |
my $cls_el = $body->create_module ($cls_res->owner_module->uri); |
1216 |
if ($cls_res->is_type_uri (ExpandedURI q<ManakaiDOM:IF>)) { |
1217 |
$cls_el = $cls_el->create_interface ($class_uri); |
1218 |
} else { |
1219 |
$cls_el = $cls_el->create_class ($class_uri); |
1220 |
} |
1221 |
for my $mem_name (keys %{$ClassMembers{$class_uri}}) { |
1222 |
my $mem_info = $ClassMembers{$class_uri}->{$mem_name}; |
1223 |
my $el; |
1224 |
if ($mem_info->{type} eq 'const-group') { |
1225 |
$el = $cls_el->create_const_group ($mem_name); |
1226 |
} elsif ($mem_info->{type} eq 'attr') { |
1227 |
$el = $cls_el->create_attribute ($mem_name); |
1228 |
} else { |
1229 |
$el = $cls_el->create_method ($mem_name); |
1230 |
} |
1231 |
if ($mem_info->{is_inherited}) { |
1232 |
$el->ref ($mem_info->{resource}->uri); |
1233 |
} |
1234 |
for my $or (keys %{$mem_info->{overrides}||{}}) { |
1235 |
$el->append_new_overrides ($or); |
1236 |
} |
1237 |
for my $or (keys %{$mem_info->{implements}||{}}) { |
1238 |
$el->append_new_implements ($or); |
1239 |
} |
1240 |
} # members |
1241 |
} # classes |
1242 |
|
1243 |
verbose_msg q<done>; |
1244 |
undef %ClassMembers; |
1245 |
} |
1246 |
|
1247 |
{ |
1248 |
status_msg_ qq<Writing file ""...>; |
1249 |
|
1250 |
require Encode; |
1251 |
my $lsimpl = $impl->get_feature (ExpandedURI q<DOMLS:LS> => '3.0'); |
1252 |
my $serializer = $lsimpl->create_mls_serializer |
1253 |
({ExpandedURI q<DOMLS:SerializeDocumentInstance> => ''}); |
1254 |
my $serialized = $serializer->write_to_string ($doc); |
1255 |
print STDOUT Encode::encode ('utf8', $serialized); |
1256 |
close STDOUT; |
1257 |
status_msg qq<done>; |
1258 |
} |
1259 |
|
1260 |
verbose_msg_ qq<Checking undefined resources...>; |
1261 |
$db->check_undefined_resource; |
1262 |
verbose_msg qq<done>; |
1263 |
|
1264 |
verbose_msg_ qq<Closing database...>; |
1265 |
$db->free; |
1266 |
undef $db; |
1267 |
verbose_msg qq<done>; |
1268 |
|
1269 |
END { |
1270 |
$db->free if $db; |
1271 |
} |
1272 |
|
1273 |
=head1 SEE ALSO |
1274 |
|
1275 |
L<lib/manakai/dis.pl> and L<bin/cdis2pm.pl> - Old version of |
1276 |
this script. |
1277 |
|
1278 |
L<lib/Message/Util/DIS.dis> - The I<dis> object implementation. |
1279 |
|
1280 |
L<lib/Message/Util/PerlCode.dis> - The Perl code generator. |
1281 |
|
1282 |
L<lib/manakai/DISCore.dis> - The definition for the "dis" format. |
1283 |
|
1284 |
L<lib/manakai/DISPerl.dis> - The definition for the "dis" Perl-specific |
1285 |
vocabulary. |
1286 |
|
1287 |
=head1 LICENSE |
1288 |
|
1289 |
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
1290 |
|
1291 |
This program is free software; you can redistribute it and/or |
1292 |
modify it under the same terms as Perl itself. |
1293 |
|
1294 |
=cut |
1295 |
|
1296 |
1; # $Date: 2005/09/01 17:07:20 $ |