| 1 |
wakaba |
1.1 |
|
| 2 |
wakaba |
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 |
wakaba |
1.1 |
package SuikaWiki::DB::Util; |
| 16 |
wakaba |
1.2 |
use strict; |
| 17 |
wakaba |
1.3 |
our $VERSION=do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
| 18 |
wakaba |
1.1 |
our $Err; |
| 19 |
|
|
|
| 20 |
wakaba |
1.2 |
=head1 FUNCTIONS |
| 21 |
wakaba |
1.1 |
|
| 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 |
wakaba |
1.2 |
$Err = Message::Util::Error->new ({ |
| 36 |
wakaba |
1.1 |
## 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 |
wakaba |
1.3 |
DB_WROTE => { |
| 55 |
|
|
level => 'detaillog', |
| 56 |
|
|
description => 'Wrote successfully', |
| 57 |
|
|
}, |
| 58 |
wakaba |
1.1 |
DB_CLOSE => { |
| 59 |
|
|
level => 'warn', |
| 60 |
|
|
description => q(Can't close database), |
| 61 |
|
|
}, |
| 62 |
wakaba |
1.3 |
DB_CLOSED => { |
| 63 |
|
|
level => 'detaillog', |
| 64 |
|
|
description => q(DB is closed successfully), |
| 65 |
|
|
}, |
| 66 |
|
|
DB_DESTROY => { |
| 67 |
|
|
level => 'detaillog', |
| 68 |
|
|
description => q(instance of DB is destroyed), |
| 69 |
|
|
}, |
| 70 |
wakaba |
1.1 |
LOCK_START => { |
| 71 |
|
|
level => 'fatal', |
| 72 |
|
|
description => q(Can't lock), |
| 73 |
|
|
}, |
| 74 |
|
|
LOCK_END => { |
| 75 |
|
|
level => 'warn', |
| 76 |
|
|
description => q(Can't unlock), |
| 77 |
|
|
}, |
| 78 |
|
|
KEY_INVALID_NAME => { |
| 79 |
|
|
level => 'stop', |
| 80 |
|
|
description => q(Invalid key name), |
| 81 |
|
|
}, |
| 82 |
|
|
KEY_INVALID_NS_NAME => { |
| 83 |
|
|
level => 'stop', |
| 84 |
|
|
description => q(Invalid key namespace), |
| 85 |
|
|
}, |
| 86 |
|
|
KEY_SAVE => { |
| 87 |
|
|
level => 'stop', |
| 88 |
wakaba |
1.3 |
description => q(Can't save to the database), |
| 89 |
wakaba |
1.1 |
}, |
| 90 |
wakaba |
1.3 |
KEY_SAVE_LOCKED => { |
| 91 |
|
|
level => 'stop', |
| 92 |
|
|
description => q(Can't save to the database because it is locked), |
| 93 |
|
|
}, |
| 94 |
wakaba |
1.1 |
UNKNOWN => { |
| 95 |
|
|
level => 'fatal', |
| 96 |
|
|
description => 'Unknown error', |
| 97 |
|
|
}, |
| 98 |
|
|
-error_handler => $opt{-error_handler}, |
| 99 |
wakaba |
1.2 |
}); |
| 100 |
|
|
$Err; |
| 101 |
wakaba |
1.1 |
} |
| 102 |
|
|
|
| 103 |
wakaba |
1.2 |
=item $locker = SuikaWiki::DB::Util->new_lock ($options) |
| 104 |
wakaba |
1.1 |
|
| 105 |
|
|
Returns new locker object (SuikaWiki::DB::Util::Lock instance). |
| 106 |
|
|
|
| 107 |
|
|
=cut |
| 108 |
|
|
|
| 109 |
|
|
sub new_lock ($$) { |
| 110 |
|
|
require SuikaWiki::DB::Util::Lock; |
| 111 |
|
|
return SuikaWiki::DB::Util::Lock->new (%{$_[1]}); |
| 112 |
|
|
} |
| 113 |
|
|
|
| 114 |
|
|
=back |
| 115 |
|
|
|
| 116 |
|
|
=cut |
| 117 |
|
|
|
| 118 |
wakaba |
1.2 |
=head1 SEE ALSO |
| 119 |
|
|
|
| 120 |
|
|
C<SuikaWiki::DB> |
| 121 |
|
|
|
| 122 |
|
|
=head1 AUTHOR |
| 123 |
|
|
|
| 124 |
|
|
Wakaba <w@suika.fam.cx>. |
| 125 |
|
|
|
| 126 |
|
|
=head1 LICENSE |
| 127 |
|
|
|
| 128 |
|
|
Copyright AUTHOR 2003. |
| 129 |
|
|
|
| 130 |
|
|
This program is free software; you can redistribute it and/or |
| 131 |
|
|
modify it under the same terms as Perl itself. |
| 132 |
|
|
|
| 133 |
|
|
=cut |
| 134 |
|
|
|
| 135 |
wakaba |
1.3 |
1; # $Date: 2003/08/06 02:54:40 $ |