| 1 |
|
| 2 |
=head1 NAME |
| 3 |
|
| 4 |
SuikaWiki::DB::Util --- SuikaWiki WikiDatabase: WikiDatabase modules common utilities |
| 5 |
|
| 6 |
=head1 DESCRIPTION |
| 7 |
|
| 8 |
This module provides some functions expected to be useful for most WikiDatabase |
| 9 |
implememtation modules. |
| 10 |
|
| 11 |
This module is part of SuikaWiki. |
| 12 |
|
| 13 |
=cut |
| 14 |
|
| 15 |
package SuikaWiki::DB::Util; |
| 16 |
use strict; |
| 17 |
our $VERSION=do{my @r=(q$Revision: 1.10 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 18 |
our $Err; |
| 19 |
|
| 20 |
=head1 FUNCTIONS |
| 21 |
|
| 22 |
=over 4 |
| 23 |
|
| 24 |
=item $err = SuikaWiki::DB::Util->error_handler () |
| 25 |
|
| 26 |
Returns error handler object (Message::Util::Error instance). |
| 27 |
|
| 28 |
=cut |
| 29 |
|
| 30 |
sub error_handler ($;%) { |
| 31 |
return $Err if $Err; |
| 32 |
my (undef, %opt) = @_; |
| 33 |
|
| 34 |
require Message::Util::Error; |
| 35 |
$Err = Message::Util::Error->new ({ |
| 36 |
## Error level: |
| 37 |
## - stop: cannot continue the operation (but other operations |
| 38 |
## might be able to be performed) |
| 39 |
## - fatal: cannot continue any operation anymore |
| 40 |
## - warn: simple warning or harmless error |
| 41 |
## - debug: debug message |
| 42 |
DB_OPEN => { |
| 43 |
level => 'fatal', |
| 44 |
description => q(Can't open database), |
| 45 |
}, |
| 46 |
DB_UNSUPPORTED_FORMAT => { |
| 47 |
level => 'stop', |
| 48 |
description => q(Unsupported format of database), |
| 49 |
}, |
| 50 |
DB_SAVE => { |
| 51 |
level => 'stop', |
| 52 |
description => q(Can't save database. Data might be lost), |
| 53 |
}, |
| 54 |
DB_CLOSE => { |
| 55 |
level => 'warn', |
| 56 |
description => q(Can't close database), |
| 57 |
}, |
| 58 |
LOCK_START => { |
| 59 |
level => 'fatal', |
| 60 |
description => q(Can't lock), |
| 61 |
}, |
| 62 |
LOCK_END => { |
| 63 |
level => 'warn', |
| 64 |
description => q(Can't unlock), |
| 65 |
}, |
| 66 |
KEY_INVALID_NAME => { |
| 67 |
level => 'stop', |
| 68 |
description => q(Invalid key name), |
| 69 |
}, |
| 70 |
KEY_INVALID_NS_NAME => { |
| 71 |
level => 'stop', |
| 72 |
description => q(Invalid key namespace), |
| 73 |
}, |
| 74 |
KEY_SAVE => { |
| 75 |
level => 'stop', |
| 76 |
description => q(Can't save to database), |
| 77 |
}, |
| 78 |
UNKNOWN => { |
| 79 |
level => 'fatal', |
| 80 |
description => 'Unknown error', |
| 81 |
}, |
| 82 |
-error_handler => $opt{-error_handler}, |
| 83 |
}); |
| 84 |
$Err; |
| 85 |
} |
| 86 |
|
| 87 |
=item $locker = SuikaWiki::DB::Util->new_lock ($options) |
| 88 |
|
| 89 |
Returns new locker object (SuikaWiki::DB::Util::Lock instance). |
| 90 |
|
| 91 |
=cut |
| 92 |
|
| 93 |
sub new_lock ($$) { |
| 94 |
require SuikaWiki::DB::Util::Lock; |
| 95 |
return SuikaWiki::DB::Util::Lock->new (%{$_[1]}); |
| 96 |
} |
| 97 |
|
| 98 |
=back |
| 99 |
|
| 100 |
=cut |
| 101 |
|
| 102 |
=head1 SEE ALSO |
| 103 |
|
| 104 |
C<SuikaWiki::DB> |
| 105 |
|
| 106 |
=head1 AUTHOR |
| 107 |
|
| 108 |
Wakaba <[email protected]>. |
| 109 |
|
| 110 |
=head1 LICENSE |
| 111 |
|
| 112 |
Copyright AUTHOR 2003. |
| 113 |
|
| 114 |
This program is free software; you can redistribute it and/or |
| 115 |
modify it under the same terms as Perl itself. |
| 116 |
|
| 117 |
=cut |
| 118 |
|
| 119 |
1; # $Date: 2003/08/06 01:26:14 $ |