=head1 NAME SuikaWiki::Implementation --- SuikaWiki : Wiki Core Implementation =cut package SuikaWiki::Implementation; use strict; our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; =head1 METHODS =over 4 =item $wiki = SuikaWiki::Implementation->new () Constructs new instance of wiki implementation =cut sub new ($;%) { my $self = bless {}, shift; $self; } =item $wiki->init_plugin Prepares to use wiki plugins =cut sub init_plugin ($) { my $self = shift; require SuikaWiki::Plugin; $self->{plugin} = SuikaWiki::Plugin->new; $self->__raise_event (name => 'plugin_manager_loaded'); } =item $wiki->init_view Prepares to use wikiview =cut sub init_view ($) { my $self = shift; require SuikaWiki::View::Implementation; $self->{view} = SuikaWiki::View::Implementation->new (wiki => $self); $self->__raise_event (name => 'view_implementation_loaded'); } =item $wiki->init_db Prepares to use wiki database =cut sub init_db ($) { my $self = shift; $self->{config}->{lock} = {-directory => $self->{config}->{path_to}->{db__lock__dir}, -retry => 20, -error_handler => sub { my ($self, %o) = @_; if ($self->{config}->{path_to}->{db__content__error_log}) { open LOG, '>>', $self->{config}->{path_to} ->{db__content__error_log}; print LOG scalar (gmtime), "\@@{[time]} @{[$$]} {$o{level}}: LOCK: ", $o{msg}, "\n"; close LOG; } if ($o{level} eq 'fatal') { die $o{msg}; } }, }; $self->{var}->{db}->{lock_prop} = sub { my $prop = shift; my %lock = %{$self->{config}->{lock}}; $lock{-name} = $prop; $lock{-share} = defined $self->{var}->{db}->{read_only}->{$prop} ? $self->{var}->{db}->{read_only}->{$prop} : $self->{var}->{db}->{read_only}->{'#default'}; \%lock; }; require SuikaWiki::DB::Util; SuikaWiki::DB::Util->error_handler->{-error_handler} = sub { my ($self, $err_type, $err_msg, $err) = @_; $err_msg = caller (3) . '-->' . caller (2) . '-->' . caller (1) . ($err->{method} ? '->'.$err->{method} : '') . ': ' . (defined $err->{file} ? $err->{file} . ': ' : '') . (defined $err->{prop} ? $err->{prop} . ': ' : '') . (defined $err->{key} ? join ('//', @{$err->{key}}) . ': ' : '') . $err_msg; if ($self->{config}->{path_to}->{db__content__error_log}) { open LOG, '>>', $self->{config}->{path_to}->{db__content__error_log}; print LOG scalar (gmtime), " @{[$$]} {$err_type->{level}}: ", $err_msg, "\n"; close LOG; } if ($err_type->{level} eq 'fatal' || $err_type->{level} eq 'stop') { die $err_msg; } }; require SuikaWiki::DB::Logical; $self->{db} = new SuikaWiki::DB::Logical; $self->__raise_event (name => 'database_loaded'); } sub __raise_event ($%) { my ($self, %o) = @_; for (@{$self->{event}->{$o{name}}||[]}) { &{$_} (@{$o{argv}||[]}); ## TODO: canceling } 1; } =item $wiki->exit Exits wiki =cut sub exit ($) { my $self = shift; if ($self->__raise_event (name => 'close')) { $self->{db}->close if ref $self->{db}; undef $self->{db}; } } sub DESTROY ($) { my $self = shift; if (ref $self->{db}) { $self->exit; } } =back =head1 PUBLIC PROPERTIES =over 4 =item $wiki->{config}->{lock} Default (prototype) properties to give SuikaWiki::DB::Util::Lock =item $wiki->{config}->{path_to}->{ $name } Filesystem path (or path fragment) to $name =item $wiki->{db} Wiki main database =item @{$wiki->{event}->{ $event_name }} Event handling procedures =cut =head1 LICENSE Copyright 2003 Wakaba This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2003/10/05 11:55:29 $