/[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.4 - (hide annotations) (download)
Sat Oct 25 06:37:52 2003 UTC (21 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +3 -2 lines
Replace '-' in name with '_'

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.4 our $VERSION = do{my @r=(q$Revision: 1.3 $=~/\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 wakaba 1.4 $name =~ tr/-/_/;
110 wakaba 1.2 join '',
111     map {$_->{Main}}
112     sort {$a->{Order} <=> $b->{Order}}
113 wakaba 1.3 @{$TemplateFragment{$name}||[]};
114 wakaba 1.2 }
115    
116 wakaba 1.1 =item $v->{definition}->{ $mode } = [{ condition => {mode => $mode,...}, ... },...]
117    
118     =item $v->{wiki}
119    
120     Instance of wiki implementation
121    
122     =back
123    
124     =cut
125    
126     package SuikaWiki::View::template;
127    
128     sub new ($%) {
129     my $class = shift;
130     bless {@_}, $class;
131     }
132    
133     sub main ($$) {
134     my ($self, $opt) = @_;
135 wakaba 1.2 my $opt2 = {};
136     $self->main_pre ($opt, $opt2)
137     &&
138     1
139     &&
140     $self->main_post ($opt, $opt2);
141     }
142    
143     sub main_pre ($$$) {
144     1;
145     }
146    
147     sub main_post ($$$) {
148     1;
149 wakaba 1.1 }
150    
151     =head1 LICENSE
152    
153     Copyright 2003 Wakaba <w@suika.fam.cx>
154    
155     This program is free software; you can redistribute it and/or
156     modify it under the same terms as Perl itself.
157    
158     =cut
159    
160 wakaba 1.4 1; # $Date: 2003/10/25 02:22:06 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24