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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide 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 wakaba 1.1
2     =head1 NAME
3    
4     SuikaWiki::Implementation --- SuikaWiki : Wiki Core Implementation
5    
6     =cut
7    
8     package SuikaWiki::Implementation;
9     use strict;
10     our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
11    
12     =head1 METHODS
13    
14     =over 4
15    
16     =item $wiki = SuikaWiki::Implementation->new ()
17    
18     Constructs new instance of wiki implementation
19    
20     =cut
21    
22     sub new ($;%) {
23     my $self = bless {}, shift;
24    
25     $self;
26     }
27    
28     =item $wiki->init_plugin
29    
30     Prepares to use wiki plugins
31    
32     =cut
33    
34     sub init_plugin ($) {
35     my $self = shift;
36     require SuikaWiki::Plugin;
37     $self->{plugin} = SuikaWiki::Plugin->new;
38    
39     $self->__raise_event (name => 'plugin_manager_loaded');
40     }
41    
42     =item $wiki->init_view
43    
44     Prepares to use wikiview
45    
46     =cut
47    
48     sub init_view ($) {
49     my $self = shift;
50     require SuikaWiki::View::Implementation;
51     $self->{view} = SuikaWiki::View::Implementation->new (wiki => $self);
52    
53     $self->__raise_event (name => 'view_implementation_loaded');
54     }
55    
56     =item $wiki->init_db
57    
58     Prepares to use wiki database
59    
60     =cut
61    
62     sub init_db ($) {
63     my $self = shift;
64     $self->{config}->{lock}
65     = {-directory => $self->{config}->{path_to}->{db__lock__dir},
66     -retry => 20,
67     -error_handler => sub {
68     my ($self, %o) = @_;
69     if ($self->{config}->{path_to}->{db__content__error_log}) {
70     open LOG, '>>', $self->{config}->{path_to}
71     ->{db__content__error_log};
72     print LOG scalar (gmtime),
73     "\@@{[time]} @{[$$]} {$o{level}}: LOCK: ",
74     $o{msg}, "\n";
75     close LOG;
76     }
77     if ($o{level} eq 'fatal') {
78     die $o{msg};
79     }
80     },
81     };
82     $self->{var}->{db}->{lock_prop} = sub {
83     my $prop = shift;
84     my %lock = %{$self->{config}->{lock}};
85     $lock{-name} = $prop;
86     $lock{-share} = defined $self->{var}->{db}->{read_only}->{$prop}
87     ? $self->{var}->{db}->{read_only}->{$prop}
88     : $self->{var}->{db}->{read_only}->{'#default'};
89     \%lock;
90     };
91    
92     require SuikaWiki::DB::Util;
93     SuikaWiki::DB::Util->error_handler->{-error_handler} = sub {
94     my ($self, $err_type, $err_msg, $err) = @_;
95     $err_msg = caller (3) . '-->' . caller (2) . '-->' . caller (1)
96     . ($err->{method} ? '->'.$err->{method} : '')
97     . ': '
98     . (defined $err->{file} ? $err->{file} . ': ' : '')
99     . (defined $err->{prop} ? $err->{prop} . ': ' : '')
100     . (defined $err->{key} ? join ('//', @{$err->{key}}) . ': ' : '')
101     . $err_msg;
102     if ($self->{config}->{path_to}->{db__content__error_log}) {
103     open LOG, '>>', $self->{config}->{path_to}->{db__content__error_log};
104     print LOG scalar (gmtime), " @{[$$]} {$err_type->{level}}: ",
105     $err_msg, "\n";
106     close LOG;
107     }
108     if ($err_type->{level} eq 'fatal' || $err_type->{level} eq 'stop') {
109     die $err_msg;
110     }
111     };
112    
113     require SuikaWiki::DB::Logical;
114     $self->{db} = new SuikaWiki::DB::Logical;
115    
116     $self->__raise_event (name => 'database_loaded');
117     }
118    
119     sub __raise_event ($%) {
120     my ($self, %o) = @_;
121     for (@{$self->{event}->{$o{name}}||[]}) {
122     &{$_} (@{$o{argv}||[]});
123     ## TODO: canceling
124     }
125     1;
126     }
127    
128     =item $wiki->exit
129    
130     Exits wiki
131    
132     =cut
133    
134     sub exit ($) {
135     my $self = shift;
136     if ($self->__raise_event (name => 'close')) {
137     $self->{db}->close if ref $self->{db};
138     undef $self->{db};
139     }
140     }
141    
142     sub DESTROY ($) {
143     my $self = shift;
144     if (ref $self->{db}) {
145     $self->exit;
146     }
147     }
148    
149     =back
150    
151     =head1 PUBLIC PROPERTIES
152    
153     =over 4
154    
155     =item $wiki->{config}->{lock}
156    
157     Default (prototype) properties to give SuikaWiki::DB::Util::Lock
158    
159     =item $wiki->{config}->{path_to}->{ $name }
160    
161     Filesystem path (or path fragment) to $name
162    
163     =item $wiki->{db}
164    
165     Wiki main database
166    
167     =item @{$wiki->{event}->{ $event_name }}
168    
169     Event handling procedures
170    
171     =cut
172    
173     =head1 LICENSE
174    
175     Copyright 2003 Wakaba <[email protected]>
176    
177     This program is free software; you can redistribute it and/or
178     modify it under the same terms as Perl itself.
179    
180     =cut
181    
182     1; # $Date: 2003/04/29 10:36:17 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24