=head1 NAME SuikaWiki::View::Implementation --- SuikaWiki: WikiView implementation =cut package SuikaWiki::View::Implementation; use strict; our $VERSION = do{my @r=(q$Revision: 1.4 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; our @CommonViewDefs; =head1 METHODS =over 4 =item $v = SuikaWiki::View->new Constructs new instance of WikiView implementation =cut sub new ($%) { my $class = shift; my $self = bless {@_, definition => {}}, $class; $self; } sub select ($$$) { my ($self, $mode, $opt) = @_; my $views = $self->{definition}->{$mode} || []; my @views; VIEW: for my $view (@$views) { my $point = 0; COND: for (keys %{$view->{condition}}) { next if $_ eq 'mode'; if (ref ($view->{condition}->{$_}) eq 'ARRAY') { for my $item (@{$view->{condition}->{$_}}) { if ($item eq $opt->{condition}->{$_}) { $point++; next COND; } } next VIEW; # no match } elsif ($opt->{condition}->{$_} eq $view->{condition}->{$_}) { $point++; } else { next VIEW; # no match } } $views[$point] ||= []; push @{$views[$point]}, $view; } for (reverse 0..$#views) { for my $view (@{$views[$_]||[]}) { return $view if !$view->{check} || &{$view->{check}} ($self, $opt); } } if ($mode ne '#default') { return $self->select ('#default', $opt); } else { return undef; } } sub instantiate ($$$) { my ($self, $mode, $opt) = @_; my $view = $self->select ($mode, $opt) or return undef; unless (ref $view->{object}) { if ($view->{object_class}) { $view->{object} = $view->{object_class}->new (view => $self, viewdef => $view, opt => $opt); } else { $view->{object} = &{$view->{object_init}} ($self, $opt, $view); } } $view->{object}->{viewdef} = $view; return $view->{object}; } sub register_mode ($$$) { my ($self, $mode, $view) = @_; $view->{condition}->{mode} ||= $mode; $self->{definition}->{$mode} ||= []; push @{$self->{definition}->{$mode}}, $view; } sub init_db ($$) { my ($self, $opt) = @_; $self->{wiki}->init_db; } sub register_common_modes ($) { my ($self) = @_; for (@CommonViewDefs) { $self->register_mode ($_->{condition}->{mode} => $_); } } our %TemplateFragment; sub assemble_template ($$) { my ($self, $name) = @_; $name =~ tr/-/_/; join '', map {$_->{Main}} sort {$a->{Order} <=> $b->{Order}} @{$TemplateFragment{$name}||[]}; } =item $v->{definition}->{ $mode } = [{ condition => {mode => $mode,...}, ... },...] =item $v->{wiki} Instance of wiki implementation =back =cut package SuikaWiki::View::template; sub new ($%) { my $class = shift; bless {@_}, $class; } sub main ($$) { my ($self, $opt) = @_; my $opt2 = {}; $self->main_pre ($opt, $opt2) && 1 && $self->main_post ($opt, $opt2); } sub main_pre ($$$) { 1; } sub main_post ($$$) { 1; } =head1 LICENSE Copyright 2003 Wakaba This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2003/10/25 06:37:52 $