59 |
$code =~ s/\$$_\b/$Info->{const}->{$_}/ge; |
$code =~ s/\$$_\b/$Info->{const}->{$_}/ge; |
60 |
} |
} |
61 |
$code =~ s/__FUNCPACK__/$Info->{module_name}/g; |
$code =~ s/__FUNCPACK__/$Info->{module_name}/g; |
62 |
|
$Info->{-message_error_used} = 1 if $code =~ /\buse\s+Message::Util::Error\b/; |
63 |
|
if (not $Info->{-message_error_used} and |
64 |
|
($code =~ /\btry\s*\{/ or $code =~ /\bcatch\s*\{/)) { |
65 |
|
warn "Message::Util::Error MUST be 'use'd before 'try'...'catch' block used"; |
66 |
|
} |
67 |
$code; |
$code; |
68 |
} |
} |
69 |
sub change_package ($$) { |
sub change_package ($$) { |
133 |
\$Info{$Info{name_literal}}->{Name} = $Info{name_literal}; |
\$Info{$Info{name_literal}}->{Name} = $Info{name_literal}; |
134 |
EOH |
EOH |
135 |
for (qw/Version InterfaceVersion mkpluginVersion module_name/) { |
for (qw/Version InterfaceVersion mkpluginVersion module_name/) { |
136 |
print qq{\$Info{$Info{name_literal}}->{$_} = @{[literal $Info{$_}]};\n}; |
print qq{\$Info{$Info{name_literal}}->{@{[literal $_]}} = @{[literal $Info{$_}]};\n}; |
137 |
} |
} |
138 |
for (qw/LastModified/) { |
for (qw/LastModified Date.RCS/) { |
139 |
$Info{$_} = n11n $meta->get_attribute ($_,make_new_node=>1)->value; |
$Info{$_} = n11n $meta->get_attribute ($_,make_new_node=>1)->value; |
140 |
next unless length $Info{$_}; |
next unless length $Info{$_}; |
141 |
print qq{\$Info{$Info{name_literal}}->{$_} = } . literal $Info{$_}; |
print qq{\$Info{$Info{name_literal}}->{@{[literal $_]}} = } . literal $Info{$_}; |
142 |
print ";\n"; |
print ";\n"; |
143 |
} |
} |
144 |
for (qw/RequiredPlugin RequiredModule/) { |
for (qw/RequiredPlugin RequiredModule/) { |
167 |
if (ref $use) { |
if (ref $use) { |
168 |
print change_package \%Info, $Info{module_name}; |
print change_package \%Info, $Info{module_name}; |
169 |
print line \%Info, node_path => 'Plugin/Use'; |
print line \%Info, node_path => 'Plugin/Use'; |
170 |
print $use->inner_text, "\n"; |
print code \%Info, $use->inner_text; |
171 |
print line \%Info, reset => 1; |
print line \%Info, reset => 1; |
172 |
} |
} |
173 |
|
|
186 |
register_plugin_const ($_, \%Info); |
register_plugin_const ($_, \%Info); |
187 |
} elsif ($_->local_name eq 'Format') { |
} elsif ($_->local_name eq 'Format') { |
188 |
print "\n", make_format ($_, \%Info); |
print "\n", make_format ($_, \%Info); |
189 |
|
} elsif ($_->local_name eq 'FormattingRuleAlias') { |
190 |
|
print "\n", make_rule_alias ($_, \%Info); |
191 |
# Parameter |
# Parameter |
192 |
# PluginCategory |
# PluginCategory |
193 |
} |
} |
205 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
206 |
my $module_name = 'SuikaWiki::Format::Definition::'.$src->get_attribute_value ('ModuleName'); |
my $module_name = 'SuikaWiki::Format::Definition::'.$src->get_attribute_value ('ModuleName'); |
207 |
my $r = change_package $Info, $module_name; |
my $r = change_package $Info, $module_name; |
208 |
|
local $Info->{-message_error_used} = 0; |
209 |
$r .= qq{our \@ISA;\n}; |
$r .= qq{our \@ISA;\n}; |
210 |
if (my $isa = $src->get_attribute_value ('Inherit')) { |
if (my $isa = $src->get_attribute_value ('Inherit')) { |
211 |
for (@$isa) { |
for (@$isa) { |
282 |
$r .= qq(}\n); |
$r .= qq(}\n); |
283 |
} elsif ($_->local_name eq 'Use') { |
} elsif ($_->local_name eq 'Use') { |
284 |
$r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use); |
$r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use); |
285 |
$r .= $_->inner_text; |
$r .= code $Info, $_->inner_text; |
286 |
} |
} |
287 |
} |
} |
288 |
$r; |
$r; |
366 |
sub make_resdef ($$) { |
sub make_resdef ($$) { |
367 |
my ($src, $Info) = @_; |
my ($src, $Info) = @_; |
368 |
my $r = change_package $Info, 'SuikaWiki::Plugin::Resource'; |
my $r = change_package $Info, 'SuikaWiki::Plugin::Resource'; |
369 |
|
local $Info->{-message_error_used} = 0; |
370 |
$r .= qq{our \$BaseResource;\n}; |
$r .= qq{our \$BaseResource;\n}; |
371 |
for (@{$src->child_nodes}) { |
for (@{$src->child_nodes}) { |
372 |
if ($_->node_type eq '#element') { |
if ($_->node_type eq '#element') { |
430 |
@{[change_package $Info, $ViewProp->{pack_name}]} |
@{[change_package $Info, $ViewProp->{pack_name}]} |
431 |
our \@ISA = q#SuikaWiki::View::template#; |
our \@ISA = q#SuikaWiki::View::template#; |
432 |
EOH |
EOH |
433 |
|
local $Info->{-message_error_used} = 0; |
434 |
my $use = $src->get_attribute ('Use'); |
my $use = $src->get_attribute ('Use'); |
435 |
if (ref $use) { |
if (ref $use) { |
436 |
$r .= line $Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/Use"; |
$r .= line $Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/Use"; |
437 |
$r .= $use->inner_text . "\n\n"; |
$r .= code $Info, $use->inner_text; |
438 |
|
$r .= "\n\n"; |
439 |
} |
} |
440 |
|
|
441 |
for (@{$src->child_nodes}) { |
for (@{$src->child_nodes}) { |
600 |
} |
} |
601 |
EOH |
EOH |
602 |
my $r = change_package $Info, $Info->{module_name}; |
my $r = change_package $Info, $Info->{module_name}; |
603 |
|
local $Info->{-message_error_used} = 0; |
604 |
if (@$type == 1) { |
if (@$type == 1) { |
605 |
$type->[0] =~ tr/-/_/; |
$type->[0] =~ tr/-/_/; |
606 |
$r .= qq{\$SuikaWiki::Plugin::Rule{$type->[0]}->{$name} = $main;\n}; |
$r .= qq{\$SuikaWiki::Plugin::Rule{$type->[0]}->{$name} = $main;\n}; |
617 |
$r; |
$r; |
618 |
} |
} |
619 |
|
|
620 |
|
=item FormattingRuleAlias |
621 |
|
|
622 |
|
Generating an alias name for a formatting rule that is already loaded. |
623 |
|
Example: |
624 |
|
|
625 |
|
FormattingRuleAlias: |
626 |
|
@Category[list]: |
627 |
|
category-1 |
628 |
|
category-2 |
629 |
|
... |
630 |
|
@Name: new-rule-name |
631 |
|
@Reference: |
632 |
|
@@Category: one-of-category |
633 |
|
@@Name: one-of-name |
634 |
|
|
635 |
|
associates C<(I<category-1>, I<new-rule-name>)>, |
636 |
|
C<(I<category-2>, I<new-rule-name>)>, ... |
637 |
|
with C<(I<one-of-category>, I<one-of-name>)>. |
638 |
|
|
639 |
|
=cut |
640 |
|
|
641 |
|
sub make_rule_alias ($$) { |
642 |
|
my ($src, $Info) = @_; |
643 |
|
my $type = $src->get_attribute ('Category', make_new_node => 1)->value || []; |
644 |
|
my $name = $src->get_attribute ('Name', make_new_node => 1)->value; |
645 |
|
|
646 |
|
my $ref = $src->get_attribute ('Reference', make_new_node => 1); |
647 |
|
my $c = $ref->get_attribute_value ('Category'); |
648 |
|
my $n = $ref->get_attribute_value ('Name'); |
649 |
|
|
650 |
|
s/(?<=.)-/_/g for $n, $name; |
651 |
|
tr/-/_/ for $c, @$type; |
652 |
|
|
653 |
|
my $def = qq{\$SuikaWiki::Plugin::Rule{@{[literal $c]}}->{@{[literal $n]}} or warn qq{Formatting rule "$c/$n" not defined}}; |
654 |
|
|
655 |
|
my $r = change_package $Info, $Info->{module_name}; |
656 |
|
for my $type (@$type) { |
657 |
|
$r .= qq{\$SuikaWiki::Plugin::Rule{@{[literal $type]}}->{@{[literal $name]}} = $def;\n}; |
658 |
|
push @{$Info->{provide}->{rule}->{$type}}, $name; |
659 |
|
} |
660 |
|
$r; |
661 |
|
} |
662 |
|
|
663 |
|
|
664 |
sub random_module_name ($;$) { |
sub random_module_name ($;$) { |
665 |
my ($Info, $subname) = @_; |
my ($Info, $subname) = @_; |
670 |
sprintf ('%02d%02d%02d%02d%02d%02d', @date[5,4,3,2,1,0]), |
sprintf ('%02d%02d%02d%02d%02d%02d', @date[5,4,3,2,1,0]), |
671 |
join ('', @rand[rand@rand,rand@rand,rand@rand,rand@rand]); |
join ('', @rand[rand@rand,rand@rand,rand@rand,rand@rand]); |
672 |
} |
} |
673 |
|
|
674 |
|
=head1 NAME |
675 |
|
|
676 |
|
mkplugin2.pl - SuikaWiki: WikiPlugin Generator |
677 |
|
|
678 |
|
=head1 SYNOPSIS |
679 |
|
|
680 |
|
mkplugin2.pl pluginsrc.wp2 > plugin.pm |
681 |
|
|
682 |
|
=head1 DESCRIPTION |
683 |
|
|
684 |
|
C<mkplugin2.pl> generates WikiPlugin module as a Perl module file |
685 |
|
from WikiPlugin source description. WikiPlugin source description |
686 |
|
is described in SuikaWikiConfig/2.0 format and it contains |
687 |
|
definitions of wiki constructions (such as formatting rules and |
688 |
|
WikiView definitions) as both machine understandable code and |
689 |
|
human readable documentation. For more information, see |
690 |
|
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiPlugin>. |
691 |
|
|
692 |
|
This script is part of SuikaWiki. |
693 |
|
|
694 |
|
=head1 HISTORY AND COMPATIBILITY |
695 |
|
|
696 |
|
C<mkplugin2.pl> introduced as part of SuikaWiki 3. |
697 |
|
It converts SuikaWiki 3 WikiPlugin source descriptions |
698 |
|
(in SuikaWikiConfig/2.0) into Perl modules with SuikaWiki 3 interface. |
699 |
|
|
700 |
|
SuikaWiki 2 has C<mkplugin.pl>. It also converts WikiPlugin |
701 |
|
source descriptions into Perl modules. But it support |
702 |
|
SuikaWiki 2 format of WikiPlugin source description that differs from |
703 |
|
SuikaWiki 3 format. Wiki programming interface (not limited to |
704 |
|
WikiPlugin related one) of SuikaWiki 3 also incompatible with that |
705 |
|
of SuikaWiki 2 so that it is impossible to use SuikaWiki 2 WikiPlugin |
706 |
|
module with SuikaWiki 3 and vice versa. |
707 |
|
|
708 |
|
=head1 SEE ALSO |
709 |
|
|
710 |
|
C<SuikaWiki::Plugin>, SuikaWiki:WikiPlugin |
711 |
|
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiPlugin>. |
712 |
|
|
713 |
|
=head1 LICENSE |
714 |
|
|
715 |
|
Copyright 2003-2004 Wakaba <w@suika.fam.cx>. All rights reserved. |
716 |
|
|
717 |
|
This program is free software; you can redistribute it and/or |
718 |
|
modify it under the same terms as Perl itself. |
719 |
|
|
720 |
|
=cut |
721 |
|
|
722 |
|
1; # $Date$ |