4 |
c => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
c => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
5 |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
6 |
dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->, |
dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->, |
|
DOMLS => q<http://suika.fam.cx/~wakaba/archive/2004/dom/ls#>, |
|
7 |
dp => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#Perl/>, |
dp => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#Perl/>, |
8 |
fe => q<http://suika.fam.cx/www/2006/feature/>, |
fe => q<http://suika.fam.cx/www/2006/feature/>, |
9 |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
10 |
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
11 |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
|
test => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Test#>, |
|
12 |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
13 |
}; |
}; |
14 |
|
|
32 |
'debug' => \$Opt{debug}, |
'debug' => \$Opt{debug}, |
33 |
'dis-file-suffix=s' => \$Opt{dis_suffix}, |
'dis-file-suffix=s' => \$Opt{dis_suffix}, |
34 |
'daem-file-suffix=s' => \$Opt{daem_suffix}, |
'daem-file-suffix=s' => \$Opt{daem_suffix}, |
35 |
|
'dafs-file-suffix=s' => \$Opt{dafs_suffix}, |
36 |
'dafx-file-suffix=s' => \$Opt{dafx_suffix}, |
'dafx-file-suffix=s' => \$Opt{dafx_suffix}, |
37 |
'help' => \$Opt{help}, |
'help' => \$Opt{help}, |
38 |
'search-path|I=s' => sub { |
'search-path|I=s' => sub { |
81 |
$Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; |
$Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; |
82 |
$Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; |
$Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; |
83 |
$Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; |
$Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; |
84 |
|
$Opt{dafs_suffix} = '.dafs' unless defined $Opt{dafs_suffix}; |
85 |
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
$Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; |
86 |
require Error; |
require Error; |
87 |
$Error::Debug = 1 if $Opt{debug}; |
$Error::Debug = 1 if $Opt{debug}; |
115 |
BEGIN { $start_time = time } |
BEGIN { $start_time = time } |
116 |
|
|
117 |
use Message::Util::DIS::DNLite; |
use Message::Util::DIS::DNLite; |
|
use Message::Util::PerlCode; |
|
|
use Message::Util::DIS::Test; |
|
|
use Message::DOM::GenericLS; |
|
118 |
|
|
119 |
my $limpl = $Message::DOM::ImplementationRegistry->get_implementation |
my %feature; |
120 |
|
|
121 |
|
for (@{$Opt{create_module}}) { |
122 |
|
my (undef, undef, undef, $out_type) = @$_; |
123 |
|
|
124 |
|
if ($out_type eq 'perl-pm') { |
125 |
|
require 'manakai/daf-perl-pm.pl'; |
126 |
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
127 |
|
} elsif ($out_type eq 'perl-t') { |
128 |
|
require 'manakai/daf-perl-t.pl'; |
129 |
|
$feature{ExpandedURI q<fe:GenericLS>} = '3.0'; |
130 |
|
$feature{'+' . ExpandedURI q<DIS:TDT>} = '1.0'; |
131 |
|
$feature{'+' . ExpandedURI q<Util:PerlCode>} = '1.0'; |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
our $limpl = $Message::DOM::ImplementationRegistry->get_implementation |
136 |
({ExpandedURI q<fe:Min> => '3.0', |
({ExpandedURI q<fe:Min> => '3.0', |
|
ExpandedURI q<fe:GenericLS> => '3.0', |
|
137 |
'+' . ExpandedURI q<DIS:DNLite> => '1.0', |
'+' . ExpandedURI q<DIS:DNLite> => '1.0', |
138 |
'+' . ExpandedURI q<DIS:Core> => '1.0', |
'+' . ExpandedURI q<DIS:Core> => '1.0', |
139 |
'+' . ExpandedURI q<Util:PerlCode> => '1.0', |
%feature, |
|
'+' . ExpandedURI q<DIS:TDT> => '1.0', |
|
140 |
}); |
}); |
141 |
my $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
our $impl = $limpl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
|
my $pc = $impl->get_feature (ExpandedURI q<Util:PerlCode> => '1.0'); |
|
|
my $di = $impl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
|
|
my $tdt_parser; |
|
142 |
|
|
143 |
## --- Loading and Updating the Database |
## --- Loading and Updating the Database |
144 |
|
|
145 |
my $HasError; |
my $HasError; |
146 |
my $db = $impl->create_dis_database; |
our $db = $impl->create_dis_database; |
147 |
$db->pl_database_module_resolver (\&daf_db_module_resolver); |
$db->pl_database_module_resolver (\&daf_db_module_resolver); |
148 |
$db->dom_config->set_parameter ('error-handler' => \&daf_on_error); |
$db->dom_config->set_parameter ('error-handler' => \&daf_on_error); |
149 |
|
|
218 |
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
unless (defined $ModuleSourceDISDocument{$module_uri}) { |
219 |
daf_open_source_dis_document ($module_uri); |
daf_open_source_dis_document ($module_uri); |
220 |
} |
} |
|
daf_convert_dis_document_to_dnl_document (); |
|
221 |
} |
} |
222 |
return daf_get_referring_module_uri_list ($module_uri); |
return daf_get_referring_module_uri_list ($module_uri); |
223 |
}, |
}, |
289 |
|
|
290 |
for (@{$Opt{create_module}}) { |
for (@{$Opt{create_module}}) { |
291 |
my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_; |
my ($mod_uri, $out_file_path, $mod_for, $out_type) = @$_; |
|
unless (defined $mod_for) { |
|
|
$mod_for = $db->get_module ($mod_uri) |
|
|
->get_property_text (ExpandedURI q<dis:DefaultFor>, |
|
|
ExpandedURI q<ManakaiDOM:all>); |
|
|
} |
|
|
my $mod = $db->get_module ($mod_uri, for_arg => $mod_for); |
|
292 |
|
|
293 |
if ($out_type eq 'perl-pm') { |
if ($out_type eq 'perl-pm') { |
294 |
status_msg_ qq<Generating Perl module from <$mod_uri> for <$mod_for>...>; |
daf_perl_pm ($mod_uri, $out_file_path, $mod_for); |
|
my $pl = $mod->pl_generate_perl_module_file; |
|
|
status_msg qq<done>; |
|
|
|
|
|
my $output; |
|
|
defined $out_file_path |
|
|
? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") |
|
|
: ($output = \*STDOUT); |
|
|
|
|
|
status_msg_ sprintf qq<Writing Perl module %s...>, |
|
|
defined $out_file_path |
|
|
? q<">.$out_file_path.q<"> |
|
|
: 'to stdout'; |
|
|
print $output $pl->stringify; |
|
|
close $output; |
|
|
status_msg q<done>; |
|
295 |
} elsif ($out_type eq 'perl-t') { |
} elsif ($out_type eq 'perl-t') { |
296 |
status_msg_ qq<Generating Perl test from <$mod_uri> for <$mod_for>...>; |
daf_perl_t ($mod_uri, $out_file_path, $mod_for); |
|
my $pl = daf_generate_perl_test_file ($mod); |
|
|
status_msg qq<done>; |
|
|
|
|
|
my $cfg = $pl->owner_document->dom_config; |
|
|
$cfg->set_parameter (ExpandedURI q<pc:preserve-line-break> => 1); |
|
|
|
|
|
my $output; |
|
|
defined $out_file_path |
|
|
? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") |
|
|
: ($output = \*STDOUT); |
|
|
|
|
|
status_msg_ sprintf qq<Writing Perl test %s...>, |
|
|
defined $out_file_path |
|
|
? q<">.$out_file_path.q<"> |
|
|
: 'to stdout'; |
|
|
print $output $pl->stringify; |
|
|
close $output; |
|
|
status_msg q<done>; |
|
297 |
} |
} |
298 |
} |
} |
299 |
|
|
306 |
undef $db; |
undef $db; |
307 |
status_msg "done"; |
status_msg "done"; |
308 |
|
|
309 |
|
undef $limpl; |
310 |
|
undef $impl; |
311 |
|
|
312 |
{ |
{ |
313 |
use integer; |
use integer; |
314 |
my $time = time - $start_time; |
my $time = time - $start_time; |
447 |
sub dac_search_file_path_stem ($$$) { |
sub dac_search_file_path_stem ($$$) { |
448 |
my ($ns, $ln, $suffix) = @_; |
my ($ns, $ln, $suffix) = @_; |
449 |
require File::Spec; |
require File::Spec; |
450 |
for my $dir ('.', @{$Opt{input_search_path}->{$ns}||[]}) { |
for my $dir (@{$Opt{input_search_path}->{$ns}||[]}) { |
451 |
my $name = Cwd::abs_path |
my $name = Cwd::abs_path |
452 |
(File::Spec->canonpath |
(File::Spec->canonpath |
453 |
(File::Spec->catfile ($dir, $ln))); |
(File::Spec->catfile ($dir, $ln))); |
506 |
my ($db, $mod, $type) = @_; |
my ($db, $mod, $type) = @_; |
507 |
my $ns = $mod->namespace_uri; |
my $ns = $mod->namespace_uri; |
508 |
my $ln = $mod->local_name; |
my $ln = $mod->local_name; |
509 |
my $suffix = $type eq ExpandedURI q<dp:ModuleIndexFile> |
my $suffix = { |
510 |
? $Opt{dafx_suffix} : $Opt{daem_suffix}; |
ExpandedURI q<dp:ModuleIndexFile> => $Opt{dafx_suffix}, |
511 |
|
ExpandedURI q<dp:ModuleResourceFile> => $Opt{daem_suffix}, |
512 |
|
ExpandedURI q<dp:ModuleNodeStorageFile> => $Opt{dafs_suffix}, |
513 |
|
}->{$type} or die "Unsupported type: <$type>"; |
514 |
verbose_msg qq<Database module <$ns$ln> is requested>; |
verbose_msg qq<Database module <$ns$ln> is requested>; |
515 |
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
my $name = dac_search_file_path_stem ($ns, $ln, $suffix); |
516 |
if (defined $name) { |
if (defined $name) { |
553 |
} |
} |
554 |
} # daf_check_undefined |
} # daf_check_undefined |
555 |
|
|
|
sub daf_generate_perl_test_file ($) { |
|
|
my $mod = shift; |
|
|
my $pl = $pc->create_perl_file; |
|
|
my $pack = $pl->get_last_package ("Manakai::Test", make_new_package => 1); |
|
|
$pack->add_use_perl_module_name ("Message::Util::DIS::Test"); |
|
|
$pack->add_use_perl_module_name ("Message::Util::Error"); |
|
|
$pack->add_require_perl_module_name ($mod->pl_fully_qualified_name); |
|
|
|
|
|
$pl->source_file ($mod->get_property_text (ExpandedURI q<DIS:sourceFile>, "")); |
|
|
$pl->source_module ($mod->name_uri); |
|
|
$pl->source_for ($mod->for_uri); |
|
|
$pl->license_uri ($mod->get_property_resource (ExpandedURI q<dis:License>) |
|
|
->uri); |
|
|
|
|
|
$pack->append_code |
|
|
($pc->create_perl_statement |
|
|
('my $impl = $Message::DOM::ImplementationRegistry->get_implementation ({ |
|
|
"http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#Test" |
|
|
=> "1.0", |
|
|
})')); |
|
|
|
|
|
$pack->append_code |
|
|
(my $num_statement = $pc->create_perl_statement |
|
|
('my $test = $impl->create_test_manager')); |
|
|
|
|
|
my $total_tests = 0; |
|
|
my %processed; |
|
|
for my $res (@{$mod->get_resource_list}) { |
|
|
next if $res->owner_module ne $mod or $processed{$res->uri}; |
|
|
$processed{$res->uri} = 1; |
|
|
|
|
|
if ($res->is_type_uri (ExpandedURI q<test:Test>)) { |
|
|
if ($res->is_type_uri (ExpandedURI q<test:StandaloneTest>)) { |
|
|
$total_tests++; |
|
|
$pack->append_code ('$test->start_new_test ('); |
|
|
$pack->append_new_pc_literal ($res->name_uri || $res->uri); |
|
|
$pack->append_code (');'); |
|
|
|
|
|
$pack->append_code ('try {'); |
|
|
|
|
|
my $test_pc = $res->pl_code_fragment; |
|
|
if (not defined $test_pc) { |
|
|
die "Perl test code not defined for <".$res->uri.">"; |
|
|
} |
|
|
|
|
|
$pack->append_code_fragment ($test_pc); |
|
|
|
|
|
$pack->append_code ('$test->ok;'); |
|
|
|
|
|
$pack->append_code ('} catch Message::Util::IF::DTException with { |
|
|
## |
|
|
} otherwise { |
|
|
my $err = shift; |
|
|
warn $err; |
|
|
$test->not_ok; |
|
|
};'); |
|
|
|
|
|
} elsif ($res->is_type_uri (ExpandedURI q<test:ParserTestSet>)) { |
|
|
my $block = $pack->append_new_pc_block; |
|
|
my @test; |
|
|
|
|
|
$tdt_parser ||= $limpl->create_gls_parser |
|
|
({ |
|
|
ExpandedURI q<DIS:TDT> => '1.0', |
|
|
}); |
|
|
for my $tres (@{$res->get_child_resource_list_by_type |
|
|
(ExpandedURI q<test:ParserTest>)}) { |
|
|
$total_tests++; |
|
|
push @test, my $ttest = {entity => {}}; |
|
|
$ttest->{uri} = $tres->uri; |
|
|
for my $eres (@{$tres->get_child_resource_list_by_type |
|
|
(ExpandedURI q<test:Entity>)}) { |
|
|
my $tent = $ttest->{entity}->{$eres->uri} = {}; |
|
|
for (ExpandedURI q<test:uri>, ExpandedURI q<test:baseURI>, |
|
|
ExpandedURI q<test:value>) { |
|
|
my $v = $eres->get_property_text ($_); |
|
|
$tent->{$_} = $v if defined $v; |
|
|
} |
|
|
$ttest->{root_uri} = $eres->uri |
|
|
if $eres->is_type_uri (ExpandedURI q<test:RootEntity>) or |
|
|
not defined $ttest->{root_uri}; |
|
|
} |
|
|
|
|
|
## Result DOM tree |
|
|
my $tree_t = $tres->get_property_text (ExpandedURI q<test:domTree>); |
|
|
if (defined $tree_t) { |
|
|
$ttest->{dom_tree} = $tdt_parser->parse_string ($tree_t); |
|
|
} |
|
|
|
|
|
## Expected |DOMError|s |
|
|
for (@{$tres->get_property_value_list (ExpandedURI q<c:erred>)}) { |
|
|
my $err = $tdt_parser->parse_tdt_error_string |
|
|
($_->string_value, $db, $_, |
|
|
undef, $tres->for_uri); |
|
|
push @{$ttest->{dom_error}->{$err->{type}->{value}} ||= []}, $err; |
|
|
} |
|
|
} |
|
|
|
|
|
for ($block->append_statement |
|
|
->append_new_pc_expression ('=')) { |
|
|
$_->append_new_pc_variable ('$', undef, 'TestData') |
|
|
->variable_scope ('my'); |
|
|
$_->append_new_pc_literal (\@test); |
|
|
} |
|
|
|
|
|
my $plc = $res->pl_code_fragment; |
|
|
unless ($plc) { |
|
|
die "Resource <".$res->uri."> does not have Perl test code"; |
|
|
} |
|
|
|
|
|
$block->append_code_fragment ($plc); |
|
|
|
|
|
} # test resource type |
|
|
} # test:Test |
|
|
} |
|
|
|
|
|
$num_statement->append_code (' (' . $total_tests . ')'); |
|
|
|
|
|
return $pl; |
|
|
} # daf_generate_perl_test_file |
|
|
|
|
556 |
__END__ |
__END__ |
557 |
|
|
558 |
=head1 NAME |
=head1 NAME |
593 |
and then I<input.dis> file is loaded in the context of it. |
and then I<input.dis> file is loaded in the context of it. |
594 |
Otherwise, a new database is created. |
Otherwise, a new database is created. |
595 |
|
|
|
=item C<--output-file-name=I<file-name>> (Required) |
|
|
|
|
|
The |
|
|
|
|
596 |
=back |
=back |
597 |
|
|
598 |
=head1 SEE ALSO |
=head1 SEE ALSO |
599 |
|
|
|
L<bin/dac2pm.pl> - Generating Perl module from "dac" file. |
|
|
|
|
600 |
L<lib/Message/Util/DIS.dis> - The actual implementation |
L<lib/Message/Util/DIS.dis> - The actual implementation |
601 |
of the "dis" interpretation. |
of the "dis" interpretation. |
602 |
|
|
603 |
=head1 LICENSE |
=head1 LICENSE |
604 |
|
|
605 |
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
Copyright 2004-2006 Wakaba <w@suika.fam.cx>. All rights reserved. |
606 |
|
|
607 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
608 |
modify it under the same terms as Perl itself. |
modify it under the same terms as Perl itself. |