/[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.6 - (show annotations) (download)
Mon Dec 1 07:42:21 2003 UTC (22 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.5: +12 -2 lines
(SuikaWiki::View::Implementation::error): New package

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 our $VERSION = do{my @r=(q$Revision: 1.5 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11 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 COND: for (keys %{$view->{condition}}) {
37 next if $_ eq 'mode';
38 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 $point++;
48 } else {
49 next VIEW; # no match
50 }
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 our %TemplateFragment;
107 sub assemble_template ($$) {
108 my ($self, $name) = @_;
109 $name =~ tr/-/_/;
110 my $template = join '',
111 map {$_->{Main}}
112 sort {$a->{Order} <=> $b->{Order}}
113 @{$TemplateFragment{$name}||[]};
114 $template;
115 }
116
117 =item $v->{definition}->{ $mode } = [{ condition => {mode => $mode,...}, ... },...]
118
119 =item $v->{wiki}
120
121 Instance of wiki implementation
122
123 =back
124
125 =cut
126
127 package SuikaWiki::View::template;
128
129 sub new ($%) {
130 my $class = shift;
131 bless {@_}, $class;
132 }
133
134 sub main ($$) {
135 my ($self, $opt) = @_;
136 my $opt2 = {};
137 $self->main_pre ($opt, $opt2)
138 &&
139 1
140 &&
141 $self->main_post ($opt, $opt2);
142 }
143
144 sub main_pre ($$$) {
145 1;
146 }
147
148 sub main_post ($$$) {
149 1;
150 }
151
152 package SuikaWiki::View::Implementation::error;
153 require Message::Util::Error;
154 our @ISA = 'Message::Util::Error';
155
156 sub ___error () {+{
157 ERROR_REPORTED => {
158
159 },
160 }}
161
162 =head1 LICENSE
163
164 Copyright 2003 Wakaba <[email protected]>
165
166 This program is free software; you can redistribute it and/or
167 modify it under the same terms as Perl itself.
168
169 =cut
170
171 1; # $Date: 2003/10/30 07:45:46 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24