/[pub]/suikawiki/script/lib/SuikaWiki/View/Implementation.pm
Suika

Contents of /suikawiki/script/lib/SuikaWiki/View/Implementation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sat Oct 25 02:22:06 2003 UTC (21 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +1 -1 lines
ErrorDocument removed

1 wakaba 1.1
2     =head1 NAME
3    
4     SuikaWiki::View::Implementation --- SuikaWiki: WikiView implementation
5    
6     =cut
7    
8     package SuikaWiki::View::Implementation;
9     use strict;
10 wakaba 1.2 our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11 wakaba 1.1 our @CommonViewDefs;
12    
13     =head1 METHODS
14    
15     =over 4
16    
17     =item $v = SuikaWiki::View->new
18    
19     Constructs new instance of WikiView implementation
20    
21     =cut
22    
23     sub new ($%) {
24     my $class = shift;
25     my $self = bless {@_, definition => {}}, $class;
26    
27     $self;
28     }
29    
30     sub select ($$$) {
31     my ($self, $mode, $opt) = @_;
32     my $views = $self->{definition}->{$mode} || [];
33     my @views;
34     VIEW: for my $view (@$views) {
35     my $point = 0;
36 wakaba 1.2 COND: for (keys %{$view->{condition}}) {
37 wakaba 1.1 next if $_ eq 'mode';
38 wakaba 1.2 if (ref ($view->{condition}->{$_}) eq 'ARRAY') {
39     for my $item (@{$view->{condition}->{$_}}) {
40     if ($item eq $opt->{condition}->{$_}) {
41     $point++;
42     next COND;
43     }
44     }
45     next VIEW; # no match
46     } elsif ($opt->{condition}->{$_} eq $view->{condition}->{$_}) {
47 wakaba 1.1 $point++;
48     } else {
49 wakaba 1.2 next VIEW; # no match
50 wakaba 1.1 }
51     }
52     $views[$point] ||= [];
53     push @{$views[$point]}, $view;
54     }
55    
56     for (reverse 0..$#views) {
57     for my $view (@{$views[$_]||[]}) {
58     return $view if !$view->{check} || &{$view->{check}} ($self, $opt);
59     }
60     }
61    
62     if ($mode ne '#default') {
63     return $self->select ('#default', $opt);
64     } else {
65     return undef;
66     }
67     }
68    
69     sub instantiate ($$$) {
70     my ($self, $mode, $opt) = @_;
71     my $view = $self->select ($mode, $opt) or return undef;
72     unless (ref $view->{object}) {
73     if ($view->{object_class}) {
74     $view->{object} = $view->{object_class}->new (view => $self,
75     viewdef => $view,
76     opt => $opt);
77     } else {
78     $view->{object} = &{$view->{object_init}} ($self, $opt, $view);
79     }
80     }
81     $view->{object}->{viewdef} = $view;
82     return $view->{object};
83     }
84    
85    
86     sub register_mode ($$$) {
87     my ($self, $mode, $view) = @_;
88     $view->{condition}->{mode} ||= $mode;
89     $self->{definition}->{$mode} ||= [];
90     push @{$self->{definition}->{$mode}}, $view;
91     }
92    
93    
94     sub init_db ($$) {
95     my ($self, $opt) = @_;
96     $self->{wiki}->init_db;
97     }
98    
99     sub register_common_modes ($) {
100     my ($self) = @_;
101     for (@CommonViewDefs) {
102     $self->register_mode ($_->{condition}->{mode} => $_);
103     }
104     }
105    
106 wakaba 1.2 our %TemplateFragment;
107     sub assemble_template ($$) {
108     my ($self, $name) = @_;
109     join '',
110     map {$_->{Main}}
111     sort {$a->{Order} <=> $b->{Order}}
112 wakaba 1.3 @{$TemplateFragment{$name}||[]};
113 wakaba 1.2 }
114    
115 wakaba 1.1 =item $v->{definition}->{ $mode } = [{ condition => {mode => $mode,...}, ... },...]
116    
117     =item $v->{wiki}
118    
119     Instance of wiki implementation
120    
121     =back
122    
123     =cut
124    
125     package SuikaWiki::View::template;
126    
127     sub new ($%) {
128     my $class = shift;
129     bless {@_}, $class;
130     }
131    
132     sub main ($$) {
133     my ($self, $opt) = @_;
134 wakaba 1.2 my $opt2 = {};
135     $self->main_pre ($opt, $opt2)
136     &&
137     1
138     &&
139     $self->main_post ($opt, $opt2);
140     }
141    
142     sub main_pre ($$$) {
143     1;
144     }
145    
146     sub main_post ($$$) {
147     1;
148 wakaba 1.1 }
149    
150     =head1 LICENSE
151    
152     Copyright 2003 Wakaba <w@suika.fam.cx>
153    
154     This program is free software; you can redistribute it and/or
155     modify it under the same terms as Perl itself.
156    
157     =cut
158    
159 wakaba 1.2 1; # $Date: 2003/10/05 11:55:29 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24