/[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.1 - (show annotations) (download)
Sun Oct 5 11:55:29 2003 UTC (22 years, 9 months ago) by wakaba
Branch: MAIN
Some temporary modifications for SuikaWiki2

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.2 $=~/\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 for (keys %{$view->{condition}}) {
37 next if $_ eq 'mode';
38 if ($opt->{condition}->{$_} eq $view->{condition}->{$_}) {
39 $point++;
40 } else {
41 next VIEW;
42 }
43 }
44 $views[$point] ||= [];
45 push @{$views[$point]}, $view;
46 }
47
48 for (reverse 0..$#views) {
49 for my $view (@{$views[$_]||[]}) {
50 return $view if !$view->{check} || &{$view->{check}} ($self, $opt);
51 }
52 }
53
54 if ($mode ne '#default') {
55 return $self->select ('#default', $opt);
56 } else {
57 return undef;
58 }
59 }
60
61 sub instantiate ($$$) {
62 my ($self, $mode, $opt) = @_;
63 my $view = $self->select ($mode, $opt) or return undef;
64 unless (ref $view->{object}) {
65 if ($view->{object_class}) {
66 $view->{object} = $view->{object_class}->new (view => $self,
67 viewdef => $view,
68 opt => $opt);
69 } else {
70 $view->{object} = &{$view->{object_init}} ($self, $opt, $view);
71 }
72 }
73 $view->{object}->{viewdef} = $view;
74 return $view->{object};
75 }
76
77
78 sub register_mode ($$$) {
79 my ($self, $mode, $view) = @_;
80 $view->{condition}->{mode} ||= $mode;
81 $self->{definition}->{$mode} ||= [];
82 push @{$self->{definition}->{$mode}}, $view;
83 }
84
85
86 sub init_db ($$) {
87 my ($self, $opt) = @_;
88 $self->{wiki}->init_db;
89 }
90
91 sub register_common_modes ($) {
92 my ($self) = @_;
93 for (@CommonViewDefs) {
94 $self->register_mode ($_->{condition}->{mode} => $_);
95 }
96 }
97
98 =item $v->{definition}->{ $mode } = [{ condition => {mode => $mode,...}, ... },...]
99
100 =item $v->{wiki}
101
102 Instance of wiki implementation
103
104 =back
105
106 =cut
107
108 package SuikaWiki::View::template;
109
110 sub new ($%) {
111 my $class = shift;
112 bless {@_}, $class;
113 }
114
115 sub main ($$) {
116 my ($self, $opt) = @_;
117 }
118
119 =head1 LICENSE
120
121 Copyright 2003 Wakaba <[email protected]>
122
123 This program is free software; you can redistribute it and/or
124 modify it under the same terms as Perl itself.
125
126 =cut
127
128 1; # $Date: 2003/04/29 10:36:17 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24