#!/usr/bin/perl -w use strict; =head1 NAME dac2pm - Generating Perl Module from "dac" File =head1 SYNOPSIS perl path/to/dac2pm.pl input.dac \ --module-uri=module-uri [--for=for-uri] [options] > ModuleName.pm perl path/to/dac2pm.pl input.dac \ --module-uri=module-uri [--for=for-uri] [options] \ --output-file-path=ModuleName.pm perl path/to/dac2pm.pl input.dac \ --create-perl-module="module-uri ModuleName.pm [for-uri]" \ [--create-perl-module="..." ...] perl path/to/dac2pm.pl --help =head1 DESCRIPTION The C script generates Perl modules from a "dac" database file created by C. This script is part of manakai. =cut use strict; use Message::Util::QName::Filter { DIS => q, dis => q, ManakaiDOM => q, Markup => q, Util => q, }; =head1 OPTIONS =over 4 =item --enable-assertion / --noenable-assertion (default) Whether assertion codes should be outputed or not. =item --create-perl-module="I I [I]" (Zero or more) The C<--create-perl-module> option can be used to specify I<--module-uri>, I<--output-file-path>, and I<--for> options once. Its value is a space-separated triplet of "dis" module name URI, Perl module file path (environment dependent), and optional "dis" module "for" URI. This option can be specified more than once; it would make multiple Perl module files to be created. If both I<--module-uri> and this options are specified, I<--module-uri>, I<--output-file-path>, and I<--for> options are treated as if there is another I<--create-perl-module> option specified. =item --for=I (Optional) Specifies the "For" URI reference for which the outputed module is. If this parameter is ommitted, the default "For" URI reference for the module specified by the C attribute of the C element, if any, or C is assumed. =item --help Shows the help message. =item --module-uri=I A URI reference that identifies a module from which a Perl module file is generated. This argument is I. =item --output-file-path=I (default: the standard output) A platform-dependent file path to which the Perl module is written down. =item --verbose / --noverbose (default) Whether a verbose message mode should be selected or not. =back =cut use Getopt::Long; use Pod::Usage; my %Opt = ( create_module => [], ); GetOptions ( 'create-perl-module=s' => sub { shift; push @{$Opt{create_module}}, [split /\s+/, shift, 3]; }, 'enable-assertion!' => \$Opt{outputAssertion}, 'for=s' => \$Opt{For}, 'help' => \$Opt{help}, 'module-uri=s' => \$Opt{module_uri}, 'output-file-path=s' => \$Opt{output_file_name}, 'verbose!' => $Opt{verbose}, ) or pod2usage (2); pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help}; $Opt{file_name} = shift; pod2usage ({-exitval => 2, -verbose => 0}) unless $Opt{file_name}; if ($Opt{module_uri}) { push @{$Opt{create_module}}, [$Opt{module_uri}, $Opt{output_file_name}, $Opt{For}]; } pod2usage (2) unless @{$Opt{create_module}}; sub status_msg ($) { my $s = shift; $s .= "\n" unless $s =~ /\n$/; print STDERR $s; } sub status_msg_ ($) { my $s = shift; print STDERR $s; } sub verbose_msg ($) { my $s = shift; $s .= "\n" unless $s =~ /\n$/; print STDERR $s if $Opt{verbose}; } sub verbose_msg_ ($) { my $s = shift; print STDERR $s if $Opt{verbose}; } ## TODO: Assertion control use Message::Util::DIS::DNLite; my $impl = $Message::DOM::ImplementationRegistry->get_implementation ({ ExpandedURI q => '3.0', '+' . ExpandedURI q => '1.0', '+' . ExpandedURI q => '1.0', }); my $pc = $impl->get_feature (ExpandedURI q => '1.0'); my $di = $impl->get_feature (ExpandedURI q => '1.0'); status_msg_ qq; my $db = $di->pl_load_dis_database ($Opt{file_name}); status_msg q; for (@{$Opt{create_module}}) { my ($mod_uri, $out_file_path, $mod_for) = @$_; my $mod = $db->get_module ($mod_uri, for_arg => $mod_for); unless ($mod_for) { $mod_for = $mod->get_property_text (ExpandedURI q, undef); if (defined $mod_for) { $mod = $db->get_module ($mod_uri, for_arg => $mod_for); } } unless ($mod->is_defined) { die qq<$0: Module <$mod_uri> for <$mod_for> is not defined>; } 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; } # create_module status_msg_ "Checking undefined resources..."; $db->check_undefined_resource; status_msg q; status_msg_ "Closing the database..."; $db->free; undef $db; status_msg q; =head1 SEE ALSO L - The object implementation. L - The object implementation, submodule for Perl modules. L - The Perl code generator. L - The definition for the "dis" format. L - The definition for the "dis" Perl-specific vocabulary. L - The "dac" database generator. =head1 LICENSE Copyright 2004-2005 Wakaba . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2005/09/22 11:02:31 $