| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
package SuikaWiki::DB::Util; |
| 3 |
|
|
|
| 4 |
|
|
our $Err; |
| 5 |
|
|
|
| 6 |
|
|
=head1 PROCEDURES |
| 7 |
|
|
|
| 8 |
|
|
=over 4 |
| 9 |
|
|
|
| 10 |
|
|
=item $err = SuikaWiki::DB::Util->error_handler () |
| 11 |
|
|
|
| 12 |
|
|
Returns error handler object (Message::Util::Error instance). |
| 13 |
|
|
|
| 14 |
|
|
=cut |
| 15 |
|
|
|
| 16 |
|
|
sub error_handler ($;%) { |
| 17 |
|
|
return $Err if $Err; |
| 18 |
|
|
my (undef, %opt) = @_; |
| 19 |
|
|
|
| 20 |
|
|
require Message::Util::Error; |
| 21 |
|
|
$Err = Message::Util::Error->new ( |
| 22 |
|
|
## Error level: |
| 23 |
|
|
## - stop: cannot continue the operation (but other operations |
| 24 |
|
|
## might be able to be performed) |
| 25 |
|
|
## - fatal: cannot continue any operation anymore |
| 26 |
|
|
## - warn: simple warning or harmless error |
| 27 |
|
|
## - debug: debug message |
| 28 |
|
|
DB_OPEN => { |
| 29 |
|
|
level => 'fatal', |
| 30 |
|
|
description => q(Can't open database), |
| 31 |
|
|
}, |
| 32 |
|
|
DB_UNSUPPORTED_FORMAT => { |
| 33 |
|
|
level => 'stop', |
| 34 |
|
|
description => q(Unsupported format of database), |
| 35 |
|
|
}, |
| 36 |
|
|
DB_SAVE => { |
| 37 |
|
|
level => 'stop', |
| 38 |
|
|
description => q(Can't save database. Data might be lost), |
| 39 |
|
|
}, |
| 40 |
|
|
DB_CLOSE => { |
| 41 |
|
|
level => 'warn', |
| 42 |
|
|
description => q(Can't close database), |
| 43 |
|
|
}, |
| 44 |
|
|
LOCK_START => { |
| 45 |
|
|
level => 'fatal', |
| 46 |
|
|
description => q(Can't lock), |
| 47 |
|
|
}, |
| 48 |
|
|
LOCK_END => { |
| 49 |
|
|
level => 'warn', |
| 50 |
|
|
description => q(Can't unlock), |
| 51 |
|
|
}, |
| 52 |
|
|
KEY_INVALID_NAME => { |
| 53 |
|
|
level => 'stop', |
| 54 |
|
|
description => q(Invalid key name), |
| 55 |
|
|
}, |
| 56 |
|
|
KEY_INVALID_NS_NAME => { |
| 57 |
|
|
level => 'stop', |
| 58 |
|
|
description => q(Invalid key namespace), |
| 59 |
|
|
}, |
| 60 |
|
|
KEY_SAVE => { |
| 61 |
|
|
level => 'stop', |
| 62 |
|
|
description => q(Can't save to database), |
| 63 |
|
|
}, |
| 64 |
|
|
UNKNOWN => { |
| 65 |
|
|
level => 'fatal', |
| 66 |
|
|
description => 'Unknown error', |
| 67 |
|
|
}, |
| 68 |
|
|
-error_handler => $opt{-error_handler}, |
| 69 |
|
|
); |
| 70 |
|
|
$err; |
| 71 |
|
|
} |
| 72 |
|
|
|
| 73 |
|
|
=item SuikaWiki::DB::Util->new_lock ($options) |
| 74 |
|
|
|
| 75 |
|
|
Returns new locker object (SuikaWiki::DB::Util::Lock instance). |
| 76 |
|
|
|
| 77 |
|
|
=cut |
| 78 |
|
|
|
| 79 |
|
|
sub new_lock ($$) { |
| 80 |
|
|
require SuikaWiki::DB::Util::Lock; |
| 81 |
|
|
return SuikaWiki::DB::Util::Lock->new (%{$_[1]}); |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
|
=back |
| 85 |
|
|
|
| 86 |
|
|
=cut |
| 87 |
|
|
|
| 88 |
|
|
1; # $Date: $ |