--- messaging/manakai/bin/daf.pl 2006/03/16 08:52:31 1.6 +++ messaging/manakai/bin/daf.pl 2006/09/10 11:19:23 1.17 @@ -4,38 +4,60 @@ c => q, DIS => q, dis => q, - DOMLS => q, dp => q, fe => q, ManakaiDOM => q, pc => q, swcfg21 => q, - test => q, Util => q, }; +our$VERSION=do{my @r=(q$Revision: 1.17 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; use Cwd; use Getopt::Long; use Pod::Usage; -my %Opt = (create_module => []); +our %Opt = (create_module => []); +my @target_modules; GetOptions ( + 'create-dtd-driver=s' => sub { + shift; + my $i = [split /\s+/, shift, 3]; + $i->[3] = 'dtd-driver'; + push @{$Opt{create_module}}, $i; + }, + 'create-dtd-modules=s' => sub { + shift; + my $i = [split /\s+/, shift, 3]; + $i->[3] = 'dtd-modules'; + push @{$Opt{create_module}}, $i; + }, 'create-perl-module=s' => sub { shift; my $i = [split /\s+/, shift, 3]; $i->[3] = 'perl-pm'; push @{$Opt{create_module}}, $i; + push @target_modules, [$i->[0], $i->[2]]; }, 'create-perl-test=s' => sub { shift; my $i = [split /\s+/, shift, 3]; $i->[3] = 'perl-t'; push @{$Opt{create_module}}, $i; + push @target_modules, [$i->[0], $i->[2]]; }, 'debug' => \$Opt{debug}, 'dis-file-suffix=s' => \$Opt{dis_suffix}, 'daem-file-suffix=s' => \$Opt{daem_suffix}, + 'dafs-file-suffix=s' => \$Opt{dafs_suffix}, 'dafx-file-suffix=s' => \$Opt{dafx_suffix}, + 'dtd-file-suffix=s' => \$Opt{dtd_suffix}, 'help' => \$Opt{help}, + 'load-module=s' => sub { + shift; + my $i = [split /\s+/, shift, 2]; + push @target_modules, [$i->[0], $i->[1]]; + }, + 'mod-file-suffix=s' => \$Opt{mod_suffix}, 'search-path|I=s' => sub { shift; my @value = split /\s+/, shift; @@ -82,6 +104,9 @@ $Opt{dis_suffix} = '.dis' unless defined $Opt{dis_suffix}; $Opt{daem_suffix} = '.dafm' unless defined $Opt{daem_suffix}; $Opt{dafx_suffix} = '.dafx' unless defined $Opt{dafx_suffix}; +$Opt{dafs_suffix} = '.dafs' unless defined $Opt{dafs_suffix}; +$Opt{dtd_suffix} = '.dtd' unless defined $Opt{dtd_suffix}; +$Opt{mod_suffix} = '.mod' unless defined $Opt{mod_suffix}; $Message::DOM::DOMFeature::DEBUG = 1 if $Opt{debug}; require Error; $Error::Debug = 1 if $Opt{debug}; @@ -115,30 +140,43 @@ BEGIN { $start_time = time } use Message::Util::DIS::DNLite; -use Message::Util::PerlCode; my %feature; -eval q{ - use Message::Util::DIS::Test; - use Message::DOM::GenericLS; - $feature{ExpandedURI q} = '3.0'; - $feature{'+' . ExpandedURI q} = '1.0'; -}; -my $limpl = $Message::DOM::ImplementationRegistry->get_implementation +for (@{$Opt{create_module}}) { + my (undef, undef, undef, $out_type) = @$_; + + if ($out_type eq 'perl-pm') { + require 'manakai/daf-perl-pm.pl'; + $feature{'+' . ExpandedURI q} = '1.0'; + } elsif ($out_type eq 'perl-t') { + require 'manakai/daf-perl-t.pl'; + $feature{ExpandedURI q} = '3.0'; + $feature{'+' . ExpandedURI q} = '1.0'; + $feature{'+' . ExpandedURI q} = '1.0'; + } elsif ($out_type eq 'dtd-modules') { + require 'manakai/daf-dtd-modules.pl'; + $feature{ExpandedURI q} = '3.0'; + $feature{'+' . ExpandedURI q} = '3.0'; + } elsif ($out_type eq 'dtd-driver') { + require 'manakai/daf-dtd-modules.pl'; + $feature{ExpandedURI q} = '3.0'; + $feature{'+' . ExpandedURI q} = '3.0'; + } +} + +our $limpl = $Message::DOM::ImplementationRegistry->get_implementation ({ExpandedURI q => '3.0', '+' . ExpandedURI q => '1.0', '+' . ExpandedURI q => '1.0', - '+' . ExpandedURI q => '1.0', %feature, }); -my $impl = $limpl->get_feature (ExpandedURI q => '1.0'); -my $tdt_parser; +our $impl = $limpl->get_feature (ExpandedURI q => '1.0'); ## --- Loading and Updating the Database my $HasError; -my $db = $impl->create_dis_database; +our $db = $impl->create_dis_database; $db->pl_database_module_resolver (\&daf_db_module_resolver); $db->dom_config->set_parameter ('error-handler' => \&daf_on_error); @@ -153,12 +191,6 @@ ## property. ); -my @target_modules; -for (@{$Opt{create_module}}) { - my ($mod_uri, $out_path, $mod_for, $out_type) = @$_; - push @target_modules, [$mod_uri, $mod_for]; -} - my $ResourceCount = 0; $db->pl_update_module (\@target_modules, get_module_index_file_name => sub { @@ -242,7 +274,7 @@ status_msg_ " " if ($ResourceCount % (10 * 10)) == 0; status_msg '' if ($ResourceCount % (10 * 50)) == 0; } -}); +}, implementation => $impl); status_msg ''; status_msg "done"; @@ -278,58 +310,21 @@ undef $DNi; undef %ModuleSourceDNLDocument; -undef $limpl; -undef $impl; exit $HasError if $HasError; ## --- Creating Files for (@{$Opt{create_module}}) { 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, - ExpandedURI q); - } - my $mod = $db->get_module ($mod_uri, for_arg => $mod_for); if ($out_type eq 'perl-pm') { - status_msg_ qq for <$mod_for>...>; - my $pl = $mod->pl_generate_perl_module_file; - status_msg qq; - - my $output; - defined $out_file_path - ? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") - : ($output = \*STDOUT); - - status_msg_ sprintf qq, - defined $out_file_path - ? q<">.$out_file_path.q<"> - : 'to stdout'; - print $output $pl->stringify; - close $output; - status_msg q; + daf_perl_pm ($mod_uri, $out_file_path, $mod_for); } elsif ($out_type eq 'perl-t') { - status_msg_ qq for <$mod_for>...>; - my $pl = daf_generate_perl_test_file ($mod); - status_msg qq; - - my $cfg = $pl->owner_document->dom_config; - $cfg->set_parameter (ExpandedURI q => 1); - - my $output; - defined $out_file_path - ? (open $output, '>', $out_file_path or die "$0: $out_file_path: $!") - : ($output = \*STDOUT); - - status_msg_ sprintf qq, - defined $out_file_path - ? q<">.$out_file_path.q<"> - : 'to stdout'; - print $output $pl->stringify; - close $output; - status_msg q; + daf_perl_t ($mod_uri, $out_file_path, $mod_for); + } elsif ($out_type eq 'dtd-modules') { + daf_dtd_modules ($mod_uri, $out_file_path, $mod_for); + } elsif ($out_type eq 'dtd-driver') { + daf_dtd_driver ($mod_uri, $out_file_path, $mod_for); } } @@ -342,6 +337,9 @@ undef $db; status_msg "done"; +undef $limpl; +undef $impl; + { use integer; my $time = time - $start_time; @@ -480,7 +478,7 @@ sub dac_search_file_path_stem ($$$) { my ($ns, $ln, $suffix) = @_; require File::Spec; - for my $dir ('.', @{$Opt{input_search_path}->{$ns}||[]}) { + for my $dir (@{$Opt{input_search_path}->{$ns}||[]}) { my $name = Cwd::abs_path (File::Spec->canonpath (File::Spec->catfile ($dir, $ln))); @@ -539,8 +537,11 @@ my ($db, $mod, $type) = @_; my $ns = $mod->namespace_uri; my $ln = $mod->local_name; - my $suffix = $type eq ExpandedURI q - ? $Opt{dafx_suffix} : $Opt{daem_suffix}; + my $suffix = { + ExpandedURI q => $Opt{dafx_suffix}, + ExpandedURI q => $Opt{daem_suffix}, + ExpandedURI q => $Opt{dafs_suffix}, + }->{$type} or die "Unsupported type: <$type>"; verbose_msg qq is requested>; my $name = dac_search_file_path_stem ($ns, $ln, $suffix); if (defined $name) { @@ -583,137 +584,6 @@ } } # daf_check_undefined -sub daf_generate_perl_test_file ($) { - my $mod = shift; - my $pc = $impl->get_feature (ExpandedURI q => '1.0'); - 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, "")); - $pl->source_module ($mod->name_uri); - $pl->source_for ($mod->for_uri); - $pl->license_uri ($mod->get_property_resource (ExpandedURI q) - ->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)) { - if ($res->is_type_uri (ExpandedURI q)) { - $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)) { - my $block = $pack->append_new_pc_block; - my @test; - - $tdt_parser ||= $limpl->create_gls_parser - ({ - ExpandedURI q => '1.0', - }); - for my $tres (@{$res->get_child_resource_list_by_type - (ExpandedURI q)}) { - $total_tests++; - push @test, my $ttest = {entity => {}}; - $ttest->{uri} = $tres->uri; - for my $eres (@{$tres->get_child_resource_list_by_type - (ExpandedURI q)}) { - my $tent = $ttest->{entity}->{$eres->uri} = {}; - for (ExpandedURI q, ExpandedURI q, - ExpandedURI q) { - my $v = $eres->get_property_text ($_); - $tent->{$_} = $v if defined $v; - } - $ttest->{root_uri} = $eres->uri - if $eres->is_type_uri (ExpandedURI q) or - not defined $ttest->{root_uri}; - } - - ## DOM configuration parameters - for my $v (@{$tres->get_property_value_list - (ExpandedURI q)}) { - my $cpuri = $v->name; - my $cp = $db->get_resource ($cpuri, for_arg => $tres->for_uri); - $ttest->{dom_config}->{$cp->get_dom_configuration_parameter_name} - = $v->get_perl_code ($block->owner_document, $tres); - } - - ## Result DOM tree - my $tree_t = $tres->get_property_text (ExpandedURI q); - if (defined $tree_t) { - $ttest->{dom_tree} = $tdt_parser->parse_string ($tree_t); - } - - ## Expected |DOMError|s - for (@{$tres->get_property_value_list (ExpandedURI q)}) { - 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 - __END__ =head1 NAME @@ -754,22 +624,16 @@ and then I file is loaded in the context of it. Otherwise, a new database is created. -=item C<--output-file-name=I> (Required) - -The - =back =head1 SEE ALSO -L - Generating Perl module from "dac" file. - L - The actual implementation of the "dis" interpretation. =head1 LICENSE -Copyright 2004-2005 Wakaba . All rights reserved. +Copyright 2004-2006 Wakaba . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.