1 |
#!/usr/bin/perl -w |
2 |
use strict; |
3 |
|
4 |
=head1 NAME |
5 |
|
6 |
dac2pm - Generating Perl Module from "dac" File |
7 |
|
8 |
=head1 SYNOPSIS |
9 |
|
10 |
perl path/to/dac2pm.pl input.dac \ |
11 |
--module-uri=module-uri [--for=for-uri] [options] > ModuleName.pm |
12 |
perl path/to/dac2pm.pl input.dac \ |
13 |
--module-uri=module-uri [--for=for-uri] [options] \ |
14 |
--output-file-path=ModuleName.pm |
15 |
perl path/to/dac2pm.pl --help |
16 |
|
17 |
=head1 DESCRIPTION |
18 |
|
19 |
The C<dac2pm> script generates a Perl module from a "dac" file. |
20 |
|
21 |
This script is part of manakai. |
22 |
|
23 |
=cut |
24 |
|
25 |
use strict; |
26 |
use Message::Util::DIS; |
27 |
use Message::Util::QName::Filter { |
28 |
DIS => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#>, |
29 |
dis => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-->, |
30 |
dis2pm => q<http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm#>, |
31 |
DISCore => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Core#>, |
32 |
DISLang => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Lang#>, |
33 |
DISPerl => q<http://suika.fam.cx/~wakaba/archive/2004/dis/Perl#>, |
34 |
disPerl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--Perl-->, |
35 |
DOMCore => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core#>, |
36 |
DOMEvents => q<http://suika.fam.cx/~wakaba/archive/2004/dom/events#>, |
37 |
DOMMain => q<http://suika.fam.cx/~wakaba/archive/2004/dom/main#>, |
38 |
DOMXML => q<http://suika.fam.cx/~wakaba/archive/2004/dom/xml#>, |
39 |
DX => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/DOMException#>, |
40 |
lang => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#>, |
41 |
Perl => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl-->, |
42 |
license => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/license#>, |
43 |
ManakaiDOM => q<http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#>, |
44 |
Markup => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup#>, |
45 |
MDOMX => q<http://suika.fam.cx/~wakaba/archive/2004/8/4/manakai-dom-exception#>, |
46 |
owl => q<http://www.w3.org/2002/07/owl#>, |
47 |
pc => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/PerlCode#>, |
48 |
rdf => q<http://www.w3.org/1999/02/22-rdf-syntax-ns#>, |
49 |
rdfs => q<http://www.w3.org/2000/01/rdf-schema#>, |
50 |
swcfg21 => q<http://suika.fam.cx/~wakaba/archive/2005/swcfg21#>, |
51 |
TreeCore => q<>, |
52 |
Util => q<http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/>, |
53 |
}; |
54 |
|
55 |
=head1 OPTIONS |
56 |
|
57 |
=over 4 |
58 |
|
59 |
=item --enable-assertion / --noenable-assertion (default) |
60 |
|
61 |
Whether assertion codes should be outputed or not. |
62 |
|
63 |
=item --for=I<for-uri> (Optional) |
64 |
|
65 |
Specifies the "For" URI reference for which the outputed module is. |
66 |
If this parameter is ommitted, the default "For" URI reference |
67 |
for the module specified by the C<dis:DefaultFor> attribute |
68 |
of the C<dis:Module> element, if any, or C<ManakaiDOM:all> is assumed. |
69 |
|
70 |
=item --help |
71 |
|
72 |
Shows the help message. |
73 |
|
74 |
=item --module-uri=I<module-uri> |
75 |
|
76 |
A URI reference that identifies a module from which a Perl |
77 |
module file is generated. This argument is I<required>. |
78 |
|
79 |
=item --output-file-path=I<perl-module-file-path> (default: the standard output) |
80 |
|
81 |
A platform-dependent file path to which the Perl module |
82 |
is written down. |
83 |
|
84 |
=item --verbose / --noverbose (default) |
85 |
|
86 |
Whether a verbose message mode should be selected or not. |
87 |
|
88 |
=back |
89 |
|
90 |
=cut |
91 |
|
92 |
use Getopt::Long; |
93 |
use Pod::Usage; |
94 |
my %Opt; |
95 |
GetOptions ( |
96 |
'enable-assertion!' => \$Opt{outputAssertion}, |
97 |
'for=s' => \$Opt{For}, |
98 |
'help' => \$Opt{help}, |
99 |
'module-uri=s' => \$Opt{module_uri}, |
100 |
'output-file-path=s' => \$Opt{output_file_name}, |
101 |
'verbose!' => $Opt{verbose}, |
102 |
) or pod2usage (2); |
103 |
pod2usage ({-exitval => 0, -verbose => 1}) if $Opt{help}; |
104 |
$Opt{file_name} = shift; |
105 |
pod2usage ({-exitval => 2, -verbose => 0}) unless $Opt{file_name}; |
106 |
pod2usage (2) unless $Opt{module_uri}; |
107 |
|
108 |
## TODO: Assertion control |
109 |
|
110 |
## TODO: Verbose mode |
111 |
|
112 |
my $impl = $Message::DOM::ImplementationRegistry->get_implementation |
113 |
({ |
114 |
ExpandedURI q<ManakaiDOM:Minimum> => '3.0', |
115 |
'+' . ExpandedURI q<DIS:Core> => '1.0', |
116 |
'+' . ExpandedURI q<Util:PerlCode> => '1.0', |
117 |
}); |
118 |
my $pc = $impl->get_feature (ExpandedURI q<Util:PerlCode> => '1.0'); |
119 |
my $di = $impl->get_feature (ExpandedURI q<DIS:Core> => '1.0'); |
120 |
|
121 |
print STDERR qq<Loading the database "$Opt{file_name}"...>; |
122 |
my $db = $di->pl_load_dis_database ($Opt{file_name}); |
123 |
print STDERR "done\n"; |
124 |
|
125 |
my $mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); |
126 |
unless ($Opt{For}) { |
127 |
$Opt{For} = $mod->get_property_text (ExpandedURI q<dis:DefaultFor>, undef); |
128 |
if (defined $Opt{For}) { |
129 |
$mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); |
130 |
} else { |
131 |
my $el = $mod->source_element; |
132 |
if ($el) { |
133 |
$Opt{For} = $el->default_for_uri; |
134 |
$mod = $db->get_module ($Opt{module_uri}, for_arg => $Opt{For}); |
135 |
} |
136 |
} |
137 |
} |
138 |
unless ($mod->is_defined) { |
139 |
die qq<$0: Module <$Opt{module_uri}> for <$Opt{For}> is not defined>; |
140 |
} |
141 |
|
142 |
my $pl = $mod->pl_generate_perl_module_file; |
143 |
|
144 |
my $output; |
145 |
defined $Opt{output_file_name} |
146 |
? (open $output, '>', $Opt{output_file_name} |
147 |
or die "$0: $Opt{output_file_name}: $!") |
148 |
: ($output = \*STDOUT); |
149 |
|
150 |
printf STDERR qq<Writing file "%s"...>, |
151 |
defined $Opt{output_file_name} ? $Opt{output_file_name} : ''; |
152 |
print $output $pl->stringify; |
153 |
close $output; |
154 |
print STDERR "done\n"; |
155 |
|
156 |
print STDERR "Checking undefined resources..."; |
157 |
$db->check_undefined_resource; |
158 |
print STDERR "done\n"; |
159 |
|
160 |
print STDERR "Closing the database..."; |
161 |
$db->free; |
162 |
undef $db; |
163 |
print STDERR "done\n"; |
164 |
|
165 |
=head1 SEE ALSO |
166 |
|
167 |
L<lib/Message/Util/DIS.dis> - The <QUOTE::dis> object implementation. |
168 |
|
169 |
L<lib/Message/Util/PerlCode.dis> - The Perl code generator. |
170 |
|
171 |
L<lib/manakai/DISCore.dis> - The definition for the "dis" format. |
172 |
|
173 |
L<lib/manakai/DISPerl.dis> - The definition for the "dis" Perl-specific |
174 |
vocabulary. |
175 |
|
176 |
L<bin/dac.pl> - The "dac" database generator. |
177 |
|
178 |
=head1 LICENSE |
179 |
|
180 |
Copyright 2004-2005 Wakaba <w@suika.fam.cx>. All rights reserved. |
181 |
|
182 |
This program is free software; you can redistribute it and/or |
183 |
modify it under the same terms as Perl itself. |
184 |
|
185 |
=cut |
186 |
|
187 |
1; # $Date: 2005/09/17 15:03:02 $ |