/[pub]/suikawiki/script/bin/mkplugin2.pl
Suika

Diff of /suikawiki/script/bin/mkplugin2.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sun Oct 5 11:11:13 2003 UTC revision 1.9 by wakaba, Fri Dec 26 06:53:48 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2  use strict;  use strict;
3  require SuikaWiki::Markup::SuikaWikiConfig20::Parser;  our $VERSION = do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4    require Message::Markup::SuikaWikiConfig20::Parser;
5    
6    {
7  my $src = '';  my $src = '';
8  my $srcfile = shift;  my $srcfile = shift;
9  open SRC, $srcfile or die "$0: $!"; {  open SRC, $srcfile or die "$0: $!"; {
# Line 11  open SRC, $srcfile or die "$0: $!"; { Line 13  open SRC, $srcfile or die "$0: $!"; {
13    
14  sub literal ($) {  sub literal ($) {
15    my $s = shift;    my $s = shift;
16    $s =~ s/([#\\])/\\$1/g;    if (ref ($s) eq 'ARRAY') {
17    q<q#> . $s . q<#>;      q<[> . list (@$s) . q<]>;
18      } elsif (ref ($s) eq 'HASH') {
19        q<{> . hash (%$s) . q<}>;
20      } elsif (ref ($s) eq 'bare') {
21        $$s;
22      } else {
23        $s =~ s/([#\\])/\\$1/g;
24        q<q#> . $s . q<#>;
25      }
26    }
27    sub list (@) {
28      join ', ', map {literal $_} @_;
29    }
30    sub hash (%) {
31      my $i = 0;
32      list map {($i++ % 2) ? $_ : do {my $s = $_; $s =~ s/(?<=.)-/_/; $s}} @_;
33  }  }
34  sub n11n ($) {  sub n11n ($) {
35    my $s = shift;    my $s = shift;
36    $s =~ s/\s+/ /g;    $s =~ s/\s+/ /g;
37    $s;    $s;
38  }  }
39    sub m13ed_val_list ($$) {
40      my ($src, $key) = @_;
41      my @r;
42      for (@{$src->child_nodes}) {
43        if ($_->local_name eq $key) {
44          push @r, [scalar $_->inner_text,
45                    scalar $_->get_attribute ('lang', make_new_node => 1)
46                             ->inner_text,
47                    scalar $_->get_attribute ('script', make_new_node => 1)
48                             ->inner_text];
49        }
50      }
51      list @r;
52    }
53    sub barecode ($) {
54      bless \$_[0], 'bare';
55    }
56    sub code ($$) {
57      my ($Info, $code) = @_;
58      for (keys %{$Info->{const}}) {
59        $code =~ s/\$$_\b/literal $Info->{const}->{$_}/ge;
60      }
61      $code =~ s/__FUNCPACK__/$Info->{module_name}/g;
62      $code;
63    }
64    sub change_package ($$) {
65      my ($Info, $pack) = @_;
66      unless ($Info->{current_package} eq $pack) {
67        $Info->{current_package} = $pack;
68        return qq{package $pack;\n\n};
69      } else {
70        return '';
71      }
72    }
73    sub quoted_string ($) {
74      my $s = shift;
75      $s =~ s/([\\"])/\\$1/g;
76      '"'.$s.'"';
77    }
78    sub line ($;%) {
79      my ($Info, %opt) = @_;
80      
81      unless ($opt{file}) {
82        if ($opt{reset}) {
83          $opt{file} = sprintf '(WikiPlugin module %s, chunk %d)',
84                               $Info->{Name},
85                               ++$Info->{chunk_count};
86        } elsif ($opt{realfile}) {
87          $opt{file} = sprintf '(WikiPlugin module %s, chunk from %s)',
88                               $Info->{Name},
89                               $opt{realfile};
90        } else {
91          $opt{file} = sprintf '(WikiPlugin module source %s, block %s)',
92                               $Info->{source_file},
93                               $opt{node_path};
94        }
95      }
96      
97      $opt{file} =~ s/"/''/g;
98      sprintf '%s#line %d "%s"%s', "\n", $opt{line_no} || 1, $opt{file}, "\n";
99    }
100    sub literal_or_code ($$) {
101      my ($Info, $s) = @_;
102      substr ($s, 0, 1) ne '{' ? literal ($s)
103                               : code ($Info, substr ($s, 1, length ($s) - 2));
104    }
105    
106  my $parser = SuikaWiki::Markup::SuikaWikiConfig20::Parser->new;  my $parser = Message::Markup::SuikaWikiConfig20::Parser->new;
107  my $plugins = $parser->parse_text ($src);  my $plugins = $parser->parse_text ($src);
108  my $meta = $plugins->get_attribute ('Plugin')  my $meta = $plugins->get_attribute ('Plugin')
109            or die "$0: Required 'Plugin' section not found";            or die "$0: Required 'Plugin' section not found";
110  my %Info = (Name => n11n $meta->get_attribute ('Name')->value);  my %Info = (provide => {},
111                Name => n11n $meta->get_attribute ('Name')->value);
112    $Info{source_file} = $srcfile;
113  $Info{name_literal} = literal $Info{Name};  $Info{name_literal} = literal $Info{Name};
114  my @date = gmtime;  my @date = gmtime;
115  $Info{LastModified} = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00',  $Info{LastModified} = sprintf '%04d-%02d-%02dT%02d:%02d:%02d+00:00',
116                                $date[5] + 1900, $date[4] + 1, @date[3,2,1,0];                                $date[5] + 1900, $date[4] + 1, @date[3,2,1,0];
117  $Info{Version} = sprintf '%04d.%02d%02d.%02d%02d',  $Info{Version} = sprintf '%04d.%02d%02d.%02d%02d',
118                           $date[5] + 1900, $date[4] + 1, @date[3,2,1];                           $date[5] + 1900, $date[4] + 1, @date[3,2,1];
119    $Info{InterfaceVersion} = '2.9.1';
120    $Info{mkpluginVersion} = '2.'.$VERSION;
121  $Info{module_name} = q#SuikaWiki::Plugin::plugin#;  $Info{module_name} = q#SuikaWiki::Plugin::plugin#;
122  $Info{module_name} = random_module_name (\%Info, $Info{Name});  $Info{module_name} = random_module_name (\%Info, $Info{Name});
123    
124  print <<EOH;  print <<EOH;
125  use strict;  use strict;
126  package SuikaWiki::Plugin::Registry;  @{[change_package \%Info, 'SuikaWiki::Plugin::Registry']}
127  our \%Info;  our \%Info;
128  \$Info{$Info{name_literal}}->{Name} = $Info{name_literal};  \$Info{$Info{name_literal}}->{Name} = $Info{name_literal};
 \$Info{$Info{name_literal}}->{Version} = q#$Info{Version}#;  
129  EOH  EOH
130  for (qw/Description LastModified License/) {  for (qw/Version InterfaceVersion mkpluginVersion module_name/) {
131      print qq{\$Info{$Info{name_literal}}->{$_} = @{[literal $Info{$_}]};\n};
132    }
133    for (qw/LastModified/) {
134    $Info{$_} = n11n $meta->get_attribute ($_,make_new_node=>1)->value;    $Info{$_} = n11n $meta->get_attribute ($_,make_new_node=>1)->value;
135    next unless length $Info{$_};    next unless length $Info{$_};
136    print qq{\$Info{$Info{name_literal}}->{$_} = } . literal $Info{$_};    print qq{\$Info{$Info{name_literal}}->{$_} = } . literal $Info{$_};
137    print ";\n";    print ";\n";
138  }  }
139  for (qw/Author RelatedURI RelatedWikiPage RequiredPlugin RequiredModule/) {  for (qw/RequiredPlugin RequiredModule/) {
140    $Info{$_} = $meta->get_attribute ($_);    $Info{$_} = $meta->get_attribute ($_);
141    next unless ref $Info{$_}; $Info{$_} = $Info{$_}->value;    next unless ref $Info{$_}; $Info{$_} = $Info{$_}->value;
142    print qq{\$Info{$Info{name_literal}}->{$_} = [};    print qq{\$Info{$Info{name_literal}}->{$_} = [};
143    print join ', ', map {literal $_} @{$Info{$_}};    print join ', ', map {literal $_} @{$Info{$_}};
144    print "];\n";    print "];\n";
145  }  }
146    for (qw/Description License RelatedWikiPage RelatedURI/) {
147      my $r = m13ed_val_list $meta, $_;
148      next unless $r;
149      print qq{\$Info{$Info{name_literal}}->{$_} = [$r];\n};
150    }
151    
152    print qq{\$Info{$Info{name_literal}}->{Author} = [} .( list map {
153            [
154              [ barecode m13ed_val_list ($_, 'Name') ],
155              [ $_->get_attribute ('Mail', make_new_node => 1)->value ],
156              [ $_->get_attribute ('URI', make_new_node => 1)->value ],
157            ]
158    } grep { $_->local_name eq 'Author' } @{$meta->child_nodes}
159    ). qq{];\n};
160    
161    my $use = $meta->get_attribute ('Use');
162    if (ref $use) {
163      print change_package \%Info, $Info{module_name};
164      print line \%Info, node_path => 'Plugin/Use';
165      print $use->inner_text, "\n";
166      print line \%Info, reset => 1;
167    }
168    
169  for (@{$plugins->child_nodes}) {  for (@{$plugins->child_nodes}) {
170    if ($_->local_name eq 'ViewDefinition') {    if ($_->local_name eq 'FormattingRule') {
171        print "\n", make_rule ($_, \%Info);
172      } elsif ($_->local_name eq 'ViewDefinition') {
173      print "\n", make_viewdef ($_, \%Info);      print "\n", make_viewdef ($_, \%Info);
174    } elsif ($_->local_name eq 'ViewFragment') {    } elsif ($_->local_name eq 'ViewFragment') {
175      print "\n", make_viewfragment ($_, \%Info);      print "\n", make_viewfragment ($_, \%Info);
176      } elsif ($_->local_name eq 'Function') {
177        print "\n", make_function ($_, \%Info);
178      } elsif ($_->local_name eq 'Resource') {
179        print "\n", make_resdef ($_, \%Info);
180      } elsif ($_->local_name eq 'PluginConst') {
181        register_plugin_const ($_, \%Info);
182      } elsif ($_->local_name eq 'Format') {
183        print "\n", make_format ($_, \%Info);
184    # Parameter
185    # PluginCategory
186    }    }
187  }  }
188    
189    print change_package \%Info, q(SuikaWiki::Plugin::Registry);
190    print qq{\$Info{$Info{name_literal}}->{provide} = } . literal $Info{provide};
191    print qq{;\n};
192    
193  print "\n1;\n";  print "\n1;\n";
194  exit;  exit;
195    }
196    
197    sub make_format ($$) {
198      my ($src, $Info) = @_;
199      my $module_name = 'SuikaWiki::Format::Definition::'.$src->get_attribute_value ('ModuleName');
200      my $r = change_package $Info, $module_name;
201      $r .= qq{our \@ISA;\n};
202      if (my $isa = $src->get_attribute_value ('Inherit')) {
203        for (@$isa) {
204          $r .= qq{push \@ISA, @{[literal 'SuikaWiki::Format::Definition::'.$_]};\n};
205        }
206      } else {
207        $r .= qq{push \@ISA, 'SuikaWiki::Format::Definition::template';\n};    
208      }
209      if (my $name = $src->get_attribute_value ('Name')) {
210        $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal '/'.$name.'/'.$src->get_attribute_value ('Version', default => '').'//']}} = '$module_name';\n};
211      }
212      if (my $type = $src->get_attribute_value ('Type')) {
213        $r .= qq{\$SuikaWiki::Format::Definition::Class{@{[literal $type.'//']}} = '$module_name';\n};
214      }
215      
216      my $convert = line $Info, line_no => __LINE__ + 2, realfile => __FILE__;
217      $convert .= <<'EOH';
218    our $Converter;
219    sub convert ($$;%) {
220      my ($self, $source, %opt) = @_;
221      my $converter;
222      my $flag = '//';
223      $flag .= 'f' if $opt{IsFragment};
224      $flag .= 'p' if $opt{IsPlaceholder};
225      if ($Converter->{$opt{Type}.$flag}) {
226        $converter = $Converter->{$opt{Type}.$flag};
227      } elsif ($Converter->{$opt{Name}.'/'.$opt{Version}.$flag}) {
228        $converter = $Converter->{'/'.$opt{Name}.'/'.$opt{Version}.$flag};
229      }
230      return $converter->{Main}->($self, $source, \%opt) if $converter;
231      $self->SUPER::convert ($source, %opt);
232    }
233    EOH
234      
235      for (@{$src->child_nodes}) {
236        if ($_->local_name eq 'Converter') {
237          if ($convert) {
238            $r .= $convert;
239            $r .= line $Info, reset => 1;
240            undef $convert;
241          }
242          $r .= make_format_converter ($_, $Info);
243        } elsif ($_->local_name eq 'Use') {
244          $r .= line $Info, node_path => qq(Format[module-name()=$module_name]/Use);
245          $r .= $_->inner_text;
246        }
247      }
248      $r;
249    }
250    
251    sub make_format_converter ($$) {
252      my ($src, $Info) = @_;
253      my %def;
254      $def{Type} = $src->get_attribute ('Type');
255      if (ref $def{Type}) {
256        $def{Type} = $def{Type}->inner_text
257              . join '', map {
258                  ';'. $_->local_name .'='. quoted_string $_->inner_text
259                } sort {
260                  $a->local_name cmp $b->local_name
261                } @{$def{Type}->child_nodes};
262      } else {
263        delete $def{Type};
264      }
265      $def{Name} = $src->get_attribute_value ('Name');
266      delete $def{Name} unless defined $def{Name};
267      $def{Version} = $src->get_attribute_value ('Version');
268      delete $def{Version} if not defined $def{Version} or
269                              not defined $def{Name};
270      
271      my $flag = '//';
272      $flag .= 'f' and $def{IsFragment} = 1
273        if $src->get_attribute_value ('IsFragment');
274      $flag .= 'p' and $def{IsPlaceholder} = 1
275        if $src->get_attribute_value ('IsPlaceholder');
276      
277      $def{Main} = $src->get_attribute_value ('Main');
278      $def{Main} = line ($Info, node_path => '//Converter/Main')
279                 . $def{Main}
280                 . line ($Info, reset => 1);
281      if ($def{Main} =~ /\$r\b/) {
282        $def{Main} = 'my $r;'."\n".$def{Main}."\n".'$r';
283      }
284      $def{Main} = barecode code $Info,
285                   'sub {my ($self, $source, $opt) = @_;'
286                 . $def{Main} . '}';
287      
288      my $r = list %def;
289      if ($def{Type}) {
290        $r = qq{\$Converter->{@{[literal $def{Type}.$flag]}} = {$r};\n};
291        $r .= qq{\$Converter->{@{[literal '/'.$def{Name}.'/'.$def{Version}.$flag]}} = \$Converter->{@{[literal $def{Type}.$flag]}};\n}
292          if $def{Name};
293      } elsif ($def{Name}) {
294        $r = qq{\$Converter->{@{[literal '/'.$def{Name}.'/'.$def{Version}.$flag]}} = {$r};\n};
295      } else {
296        $r = 'BEGIN { die "Invalid Syntax of Converter: Type or Name property required" }';
297      }
298      $r;
299    }
300    
301    sub make_function ($$) {
302      my ($src, $Info) = @_;
303      ## TODO: support of ARGV property
304      my $name;
305      my $r = <<EOH;
306    @{[change_package $Info, $Info->{module_name}]}
307    sub @{[$name = $src->get_attribute_value ('Name')]} {
308    @{[line $Info, node_path => "Function[Name='$name']/Main"]}@{[
309      code $Info, $src->get_attribute_value ('Main')
310    ]}
311    }
312    @{[line $Info, reset => 1]}
313    EOH
314    }
315    
316    sub register_plugin_const ($$) {
317      my ($src, $Info) = @_;
318      for (@{$src->child_nodes}) {
319        $Info->{const}->{$_->local_name} = $_->value;
320      }
321    }
322    
323    sub make_resdef ($$) {
324      my ($src, $Info) = @_;
325      my $r = change_package $Info, 'SuikaWiki::Plugin::Resource';
326      $r .= qq{our \$BaseResource;\n};
327      for (@{$src->child_nodes}) {
328        if ($_->node_type eq '#element') {
329          my $lang = literal ($_->get_attribute_value ('lang') || 'und');
330          my $script = literal $_->get_attribute_value ('script');
331          my $name = literal $_->local_name;
332          my $val = literal n11n $_->value;
333          $r .= qq{\$BaseResource->{$lang}->{$script}->{$name} = $val;\n};
334        }
335      }
336      $r;
337    }
338    
339  sub make_viewfragment ($$) {  sub make_viewfragment ($$) {
340    my ($src, $Info) = @_;    my ($src, $Info) = @_;
341    my $r = '';    my $r = '';
342    for (@{$src->child_nodes}) {    my $body = <<EOH;
343      ## TODO: use SuikaWiki2 interface    {
344      $r .= qq(SuikaWiki::View->template (@{[literal $_->local_name]})->add_line (@{[literal $_->value]});\n);      Main => @{[literal $src->get_attribute_value ('Formatting')]},
345        Order => @{[0+$src->get_attribute_value ('Order')]},
346        Description => [@{[m13ed_val_list $src, 'Description']}],
347      };
348    EOH
349      ## Recommended format
350      my $name = $src->get_attribute_value ('Template');
351      if (ref ($name) and @$name > 1) {
352        $r .= qq({my \$def = $body;\n);
353        for (@$name) {
354          my $name = $_; $name =~ tr/-/_/;
355          $r .= qq(push \@{\$SuikaWiki::View::Implementation::TemplateFragment{@{[literal $name]}}}, \$def;\n);
356          push @{$Info->{provide}->{viewfragment}}, {Name => $name};
357        }
358        $r .= qq(}\n);
359      } else {                           ## Obsoleted format
360        $name = ref $name ? $name->[0] : $src->get_attribute_value ('Name');
361        $name =~ tr/-/_/;
362        $r .= qq(push \@{\$SuikaWiki::View::Implementation::TemplateFragment{@{[literal $name]}}}, $body);
363        push @{$Info->{provide}->{viewfragment}}, {Name => $name};
364    }    }
365    $r;    $r;
366  }  }
# Line 80  sub make_viewdef ($$) { Line 369  sub make_viewdef ($$) {
369    my ($src, $Info) = @_;    my ($src, $Info) = @_;
370    my $ViewProp = {};    my $ViewProp = {};
371    my $r = '';    my $r = '';
372    $ViewProp->{Name} = n11n $src->get_attribute ('Mode')->value;    $ViewProp->{Name} = n11n $src->get_attribute_value ('Mode');
373    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});    $ViewProp->{pack_name} = random_module_name ($Info, $ViewProp->{Name});
374        
375    $ViewProp->{condition_stringified} = join ', ', map {literal $_}    $ViewProp->{condition_stringified} = hash
376      mode => $ViewProp->{Name},      mode => $ViewProp->{Name},
377      map {($_->local_name => $_->value)}      map {($_->local_name => $_->value)}
378        @{$src->get_attribute ('Condition',make_new_node=>1)->child_nodes};        @{$src->get_attribute ('Condition',make_new_node=>1)->child_nodes};
# Line 93  push \@SuikaWiki::View::Implementation:: Line 382  push \@SuikaWiki::View::Implementation::
382    condition => {$ViewProp->{condition_stringified}},    condition => {$ViewProp->{condition_stringified}},
383    object_class => q#$ViewProp->{pack_name}#,    object_class => q#$ViewProp->{pack_name}#,
384  };  };
385  package $ViewProp->{pack_name};  @{[change_package $Info, $ViewProp->{pack_name}]}
386  our \@ISA = q#SuikaWiki::View::template#;  our \@ISA = q#SuikaWiki::View::template#;
387  EOH  EOH
388    for (@{$src->child_nodes}) {    for (@{$src->child_nodes}) {
389      if ($_->local_name eq 'method') {      if ($_->local_name eq 'template') {
390          $r .= make_view_template_method ($_, $Info, $ViewProp);
391        } elsif ($_->local_name eq 'method') {
392          my $method_name = $_->get_attribute_value ('Name');
393        $r .= ({        $r .= ({
394                main => q(sub main ($$) {)."\n".q(my ($self, $opt) = @_;)."\n",                main => q(sub main ($$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",
395                main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                main_pre => q(sub main_pre ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",
396                main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                                    main_post => q(sub main_post ($$$) {)."\n".q(my ($self, $opt, $opt2) = @_;)."\n",                    
397               }->{$_->get_attribute ('Name')->value}               }->{$method_name}
398               ||qq(sub @{[$_->get_attribute ('Name')->value]} {\n))               ||qq(sub @{[$method_name]} {\n))
399           . $_->inner_text           . line ($Info, node_path => "ViewDefinition[Mode='$ViewProp->{Name}']/method[Name='$method_name']")
400           . qq(\n}\n);           . code ($Info, $_->value)
401             . qq(}\n)
402             . line ($Info, reset => 1);
403        }
404      }
405      my $prop = {Name => $ViewProp->{Name},
406                  Description => barecode m13ed_val_list $_, 'Description'};
407      push @{$Info->{provide}->{viewdef}}, $prop;
408      $r;
409    }
410    
411    sub make_view_template_method ($$) {
412      my ($src, $Info, $ViewProp) = @_;
413      my $r = <<EOH;
414    
415    sub main (\$\$\$) {
416      my (\$self, \$opt, \$opt2) = \@_;
417      require SuikaWiki::Output::HTTP;
418      \$opt2->{output} = SuikaWiki::Output::HTTP->new
419        (wiki => \$self->{view}->{wiki},
420         view => \$self->{view}, viewobj => \$self);
421      for (\@{\$self->{view}->{wiki}->{var}->{client}->{used_for_negotiate}},
422           'Accept-Language') {
423        \$opt2->{output}->add_negotiate_header_field (\$_);
424      }
425      
426      \$opt2->{template} = @{[literal $src->get_attribute ('body', make_new_node => 1)->inner_text]};
427      \$opt2->{o} = bless {
428                         ## Compatible options for SuikaWiki 2 WikiPlugin interface
429                           param => \\\%main::form,
430                           page => \$main::form{mypage},
431                           #toc => [],
432                           #magic
433                           #content
434                           #use_anchor_name
435                           media => {@{[hash
436        type => ($src->get_attribute ('media-type',make_new_node=>1)->inner_text
437                 || 'application/octet-stream'),
438        charset => ($src->get_attribute ('use-media-type-charset',make_new_node=>1)
439                        ->inner_text || 0),
440        ## In fact, this value is not referred from any SuikaWiki 2 WikiPlugin rule.
441        #expires => ($src->get_attribute ('expires',make_new_node=>1)->inner_text
442        #                             || 0)
443        ]}},
444                          ## SuikaWiki 3 WikiPlugin interface
445                            wiki => \$self->{view}->{wiki},
446                            plugin => \$self->{view}->{wiki}->{plugin},
447                            var => {},
448                          }, 'SuikaWiki::Plugin';  
449      @{[do{my $x=$src->get_attribute('http-status-code',make_new_node=>1)->inner_text;
450         $x?q{$opt2->{output}->{status_code} = }.(0 + $x).q{;}:q{}}]}
451      @{[do{my $x=$src->get_attribute('http-status-phrase',make_new_node=>1)->inner_text;
452         $x?q{$opt2->{output}->{status_phrase} = }.literal($x).q{;}:q{}}]}
453      \$opt2->{output}->{entity}->{media_type} = @{[literal
454                               $src->get_attribute ('media-type',make_new_node=>1)
455                                   ->inner_text || 'application/octet-stream']};
456      @{[($src->get_attribute ('use-media-type-charset',make_new_node=>1)
457                ->inner_text || 0) ?
458         q{$opt2->{output}->{entity}->{charset} = $self->{view}->{wiki}->{config}->{charset}->{output};}:
459         q{}]}
460      @{[do{my $x = $src->get_attribute ('expires',make_new_node=>1)->inner_text;
461              if ($x =~ /%%(\w+)%%/) {
462                qq{\$opt2->{output}->set_expires (%{\$self->{view}->{wiki}->{config}->{entity}->{expires}->{@{[literal $1]}}});};
463              } else {
464                qq{\$opt2->{output}->set_expires (delta => @{[0 + $x]});};
465              }
466          }]}
467      
468      \$self->{view}->{wiki}->init_db;
469      \$self->main_pre (\$opt, \$opt2);
470      
471      use Message::Util::Error;
472      try {
473        \$opt2->{output}->{entity}->{body}
474          = SuikaWiki::Plugin->formatter ('view')
475            ->replace (\$opt2->{template}, param => \$opt2->{o});
476      } \$self->{view}->{wiki}->{config}->{catch}->{ @{[
477           $ViewProp->{Name} eq '-error' ? 'formatter_view_error'
478                                         : 'formatter_view' ]} };
479      \$opt2->{output}->output (output => 'http-cgi');
480      
481      \$self->main_post (\$opt, \$opt2);
482    }
483    EOH
484    }
485    
486    sub make_rule ($$) {
487      my ($src, $Info) = @_;
488      my $type = $src->get_attribute ('Category', make_new_node => 1)->value || [];
489      my $name = $src->get_attribute ('Name', make_new_node => 1)->value;
490      $name =~ s/(?<=.)-/_/g;
491      my $main = line ($Info, node_path => "FormattingRule[name()='@{[list $type]}/$name']/Formatting")
492               . code ($Info, $src->get_attribute_value ('Formatting'));
493      
494      my $reg_block;
495      $reg_block = qr/[^{}]*(?>[^{}]+|{(??{$reg_block})})*/;
496      
497      $main = q{my ($f, $rule_name, $p, $o, %opt) = @_;}."\n".$main
498        if $main =~ /\$f\b/
499        or $main =~ /\$rule_name\b/
500        or $main =~ /\$[opr]\b/
501        or $main =~ /[%\$]opt\b/;
502      if ($main =~ /\$r\b/) {
503        warn qq(Rule @{[list $type]}/$name: Use of \$r is deprecated);
504        $main = q{my $r = '';} . "\n" . $main . "\n"
505              . q{$p->{-parent}->append_node ($r, node_or_text => 1);};
506      }
507      $main =~ s{__ATTR(TEXT|NODE)?:%(\w+|{$reg_block})(?:->{($reg_block)})?__;}
508                {($1 eq 'TEXT' ? '$p->{'.literal_or_code($Info, $2)
509                                        .'} = do { my $r = ' : '')
510                 .'$f->parse_attr ($p=>'.literal_or_code($Info, $2).', $o, '
511                                 .($3?'-parent => '.$3.', ':'')
512                                 .($1?'-non_parsed_to_node => 1, ':'')
513                                 .'%opt)'
514                                 .($1 eq 'TEXT' ? '; ref $r?$r->inner_text:$r}' : '')
515                                 .';'}ge;
516      
517      $main = <<EOH;
518    {
519      main => sub {$main},
520    @{[line ($Info, reset => 1)]}
521      Description => [@{[m13ed_val_list $src, 'Description']}],
522      Parameter => {@{[do{
523        my @r;
524        for (@{$src->child_nodes}) {
525          if ($_->local_name eq 'Parameter') {
526            push @r, $_->get_attribute_value ('Name')
527                     => {Type => $_->get_attribute_value ('Type'),
528                         Default => $_->get_attribute_value ('Default'),
529                         Description => [barecode m13ed_val_list $_, 'Description']};
530          }
531        }
532        list @r;
533      }]}},
534    }
535    EOH
536      my $r = change_package $Info, $Info->{module_name};
537      if (@$type == 1) {
538        $type->[0] =~ tr/-/_/;
539        $r .= qq{\$SuikaWiki::Plugin::Rule{$type->[0]}->{$name} = $main;\n};
540        push @{$Info->{provide}->{rule}->{$type->[0]}}, $name;
541      } else {
542        $r .= qq({my \$def = $main;\n);
543        for my $type (@$type) {
544          $type =~ tr/-/_/;
545          $r .= qq{\$SuikaWiki::Plugin::Rule{$type}->{$name} = \$def;\n};
546          push @{$Info->{provide}->{rule}->{$type}}, $name;
547      }      }
548        $r .= qq(};\n);
549    }    }
550    $r;    $r;
551  }  }
# Line 117  sub random_module_name ($;$) { Line 556  sub random_module_name ($;$) {
556    $subname =~ s/[^0-9A-Za-z_:]//g;    $subname =~ s/[^0-9A-Za-z_:]//g;
557    my @date = gmtime;    my @date = gmtime;
558    my @rand = ('A'..'Z','a'..'z',0..9,'_');    my @rand = ('A'..'Z','a'..'z',0..9,'_');
559    sprintf '%s::%s%s%s', $Info{module_name}, $subname,    sprintf '%s::%s%s%s', $Info->{module_name}, $subname,
560      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]),
561      join ('', @rand[rand@rand,rand@rand,rand@rand,rand@rand]);      join ('', @rand[rand@rand,rand@rand,rand@rand,rand@rand]);
562  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24