#!/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 --help =head1 DESCRIPTION The C script generates a Perl module from a "dac" file. This script is part of manakai. =cut use strict; use Message::Util::DIS; use Message::Util::QName::Filter { DIS => q, dis => q, dis2pm => q, DISCore => q, DISLang => q, DISPerl => q, disPerl => q, DOMCore => q, DOMEvents => q, DOMMain => q, DOMXML => q, DX => q, lang => q, Perl => q, license => q, ManakaiDOM => q, Markup => q, MDOMX => q, owl => q, pc => q, rdf => q, rdfs => q, swcfg21 => q, TreeCore => q<>, Util => q, }; =head1 OPTIONS =over 4 =item --enable-assertion / --noenable-assertion (default) Whether assertion codes should be outputed or not. =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; GetOptions ( '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}; pod2usage (2) unless $Opt{module_uri}; ## TODO: Assertion control ## TODO: Verbose mode 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'); print STDERR qq; my $db = $di->pl_load_dis_database ($Opt{file_name}); print STDERR "done\n"; my $mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); unless ($Opt{For}) { $Opt{For} = $mod->get_property_text (ExpandedURI q, undef); if (defined $Opt{For}) { $mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); } else { my $el = $mod->source_element; if ($el) { $Opt{For} = $el->default_for_uri; $mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); } } } unless ($mod->is_defined) { die qq<$0: Module <$Opt{module_uri}> for <$Opt{For}> is not defined>; } my $pl = $mod->pl_generate_perl_module_file; my $output; defined $Opt{output_file_name} ? (open $output, '>', $Opt{output_file_name} or die "$0: $Opt{output_file_name}: $!") : ($output = \*STDOUT); printf STDERR qq, defined $Opt{output_file_name} ? $Opt{output_file_name} : ''; print $output $pl->stringify; close $output; print STDERR "done\n"; print STDERR "Checking undefined resources..."; $db->check_undefined_resource; print STDERR "done\n"; print STDERR "Closing the database..."; $db->free; undef $db; print STDERR "done\n"; =head1 SEE ALSO L - The object implementation. 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/19 16:17:50 $