#!/usr/bin/perl -w use strict; =head1 NAME cdis2pm - Generating Perl Module from a Compiled "dis" =head1 SYNOPSIS perl path/to/cdis2pm.pl input.cdis \ {--module-name=ModuleName | --module-uri=module-uri} \ [--for=for-uri] [options] > ModuleName.pm perl path/to/cdis2pm.pl --help =head1 DESCRIPTION The C script generates a Perl module from a compiled "dis" ("cdis") file. It is intended to be used to generate a manakai DOM Perl module files, although it might be useful for other purpose. This script is part of manakai. =cut use strict; use Message::DOM::DOMMetaImpl; 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, }; use Message::Util::DIS; use Message::Util::PerlCode; =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, if any, or the C is assumed. =item --help Shows the help message. =item --module-name=I The name of module to output. It is the local name part of the C C in the source "dis" file. Either C<--module-name> or C<--module-uri> is required. =item --module-uri=I A URI reference that identifies a module to output. Either C<--module-name> or C<--module-uri> is required. =item --output-file-path=I (default: C) A platform-dependent file name path for the output. If it is not specified, then the generated Perl module content is outputed to the standard output. =item --output-module-version (default) / --nooutput-module-version Whether the C<$VERSION> special variable should be generated or not. =item --verbose / --noverbose (default) Whether a verbose message mode should be selected or not. =back =cut use Getopt::Long; use Pod::Usage; use Storable; my %Opt; GetOptions ( 'enable-assertion!' => \$Opt{outputAssertion}, 'for=s' => \$Opt{For}, 'help' => \$Opt{help}, 'implementation-registry-package=s' => \$Opt{implreg_pack}, 'module-uri=s' => \$Opt{module_uri}, 'output-file-path=s' => \$Opt{output_file_name}, 'output-module-version!' => \$Opt{outputModuleVersion}, '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: $Opt{outputModuleVersion} = 1 unless defined $Opt{outputModuleVersion}; ## TODO: Assertion control ## TODO: Verbose mode $Opt{implreg_pack} ||= $Message::DOM::DOMImplementationRegistry; if ($Opt{implreg_pack} eq 'Message::DOM::DOMMetaImpl::ManakaiDOMImplementationRegistryCompat') { unshift @Message::Markup::SuikaWikiConfig21::ManakaiSWCFGImplementation::ISA, 'Message::DOM::DOMMetaImpl::ManakaiDOMMinimumImplementationCompat'; } my $impl = $Opt{implreg_pack}->get_dom_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'); my $db = $di->pl_load_dis_database ($Opt{file_name}); my $mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); unless ($Opt{For}) { 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); print $output $pl->stringify; $db->check_undefined_resource; =head1 SEE ALSO L and L - Old version of this script. 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. =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/05/07 13:56:36 $