BDB-Wrapper
view release on metacpan or search on metacpan
lib/BDB/Wrapper.pm view on Meta::CPAN
734735736737738739740741742743744745746747748749750751752753754
undef
is
default
value.
If you set {
'wait'
=>wait_seconds}, you can specify the seconds in which dead
lock
will be removed.
22 is
default
value.
If you set {
'transaction'
=>transaction_root_dir}, all dbh object will be created in transaction mode
unless
you don\'t specify transaction root dir in
each
method.
0 is
default
value.
=cut
sub new(){
my $self={};
my $class=shift;
my $op_ref=shift;
$self->{'lock_root'}='/tmp/bdbwrapper';
$self->{'no_lock'}=0;
$self->{'Flags'}='';
$self->{'wait'}= 22;
$self->{'default_txn_dir'}=$self->{'lock_root'}.'/txn_data';
while(my ($key, $value)=each %{$op_ref}){
if($key eq 'ram'){
lib/BDB/Wrapper.pm view on Meta::CPAN
810811812813814815816817818819820821822823824825826827828829830
'no_lock='
>0(
default
) or 1,
'cache'
=>
undef
(
default
) or integer,
'error_log_file'
=>
undef
or
$error_log_file
,
'transaction'
=> 0==
undef
or 1 or
$transaction_root_dir
});
no_lock and cache will overwrite the value specified in new but used only in this env
=cut
sub create_env(){
my $self=shift;
my $op=shift;
my $bdb=File::Spec->rel2abs($op->{'bdb'}) || return;
my $no_lock=$op->{'no_lock'} || $self->{'no_lock'} || 0;
my $transaction=undef;
$self->{'error_log_file'}=$op->{'errore_log_file'};
if(exists($op->{'transaction'})){
$transaction=$op->{'transaction'};
}
elsif(exists($op->{'txn'})){
lib/BDB/Wrapper.pm view on Meta::CPAN
892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926}
=head2 create_dbh
Not recommened method. Please use create_read_dbh() or create_write_dbh().
Creates database handler for BerkeleyDB
This will be obsolete due to too much simplicity, so please don\'t use.
=cut
sub
create_dbh(){
my
$self
=
shift
;
my
$bdb
=File::Spec->rel2abs(
shift
);
my
$op
=
shift
;
return
$self
->create_write_dbh(
$bdb
,
$op
);
}
=head2 create_hash_ref
Not recommended method. Please use create_write_dbh().
Creates database handler for BerkeleyDB
This will be obsolete due to too much simplicity, so please don\'t use.
=cut
sub
create_hash_ref(){
my
$self
=
shift
;
my
$bdb
=File::Spec->rel2abs(
shift
);
my
$op
=
shift
;
return
$self
->create_write_hash_ref(
$bdb
,
$op
);
}
=head2 create_write_dbh
This returns database handler for writing or ($database_handler, $env) depeinding on the request.
lib/BDB/Wrapper.pm view on Meta::CPAN
948949950951952953954955956957958959960961962963964965966967968
If you set
sort
or sort_num 1, you can
use
sub
{
$_
[0] <=>
$_
[1]}
for
sort_code_ref.
If you set
reverse
or reverse_num 1, you can
use
sub
{
$_
[1] <=>
$_
[0]}
for
sort_code_ref.
If you set reverse_cmp 1, you can
use
sub
{
$_
[1] cmp
$_
[0]}
for
sort_code_ref.
If you set transaction
for
storing transaction
log
, transaction will be used and (
$bdb_handler
,
$transaction_handler
) will be returned.
=cut
sub create_write_dbh(){
my $self=shift;
my $bdb=shift;
my $op='';
if($bdb && ref($bdb) eq 'HASH'){
$op=$bdb;
$bdb=$op->{'bdb'};
}
else{
$op=shift;
$op->{'bdb'}=$bdb;
lib/BDB/Wrapper.pm view on Meta::CPAN
113311341135113611371138113911401141114211431144114511461147114811491150115111521153
If you set
sort
or sort_num 1, you can
use
sub
{
$_
[0] <=>
$_
[1]}
for
sort_code_ref.
If you set
reverse
or reverse_num 1, you can
use
sub
{
$_
[1] <=>
$_
[0]}
for
sort_code_ref.
If you set reverse_cmp 1, you can
use
sub
{
$_
[1] cmp
$_
[0]}
for
sort_code_ref.
If you set transaction 1, you will
use
/tmp/bdbwrapper/txn_data
for
the storage of transaction.
=cut
sub create_read_dbh(){
my $self=shift;
my $bdb=shift;
my $op='';
my $transaction=undef;
if($bdb && ref($bdb) eq 'HASH'){
$op=$bdb;
$bdb=$op->{'bdb'};
}
else{
$op=shift;
lib/BDB/Wrapper.pm view on Meta::CPAN
128112821283128412851286128712881289129012911292129312941295129612971298129913001301
If you set sort_code_ref some code reference, you can set subroutine
for
sorting
for
Btree.
If you set
sort
or sort_num 1, you can
use
sub
{
$_
[0] <=>
$_
[1]}
for
sort_code_ref.
If you set
reverse
or reverse_num 1, you can
use
sub
{
$_
[1] <=>
$_
[0]}
for
sort_code_ref.
If you set reverse_cmp 1, you can
use
sub
{
$_
[1] cmp
$_
[0]}
for
sort_code_ref.
=cut
sub create_write_hash_ref(){
my $self=shift;
my $bdb=shift;
my $op='';
if($bdb && ref($bdb) eq 'HASH'){
$op=$bdb;
$bdb=$op->{'bdb'};
}
else{
$op=shift;
}
lib/BDB/Wrapper.pm view on Meta::CPAN
142514261427142814291430143114321433143414351436143714381439144014411442144314441445
If you set
sort
or sort_num 1, you can
use
sub
{
$_
[0] <=>
$_
[1]}
for
sort_code_ref.
If you set
reverse
or reverse_num 1, you can
use
sub
{
$_
[1] <=>
$_
[0]}
for
sort_code_ref.
If you set reverse_cmp 1, you can
use
sub
{
$_
[1] cmp
$_
[0]}
for
sort_code_ref.
=cut
sub create_read_hash_ref(){
my $self=shift;
my $bdb=shift;
my $op='';
if($bdb && ref($bdb) eq 'HASH'){
$op=$bdb;
$bdb=$op->{'bdb'};
}
else{
$op=shift;
}
lib/BDB/Wrapper.pm view on Meta::CPAN
152615271528152915301531153215331534153515361537153815391540154115421543154415451546}
=head2 rmkdir
Code from CGI::Accessup.
This creates the specified directory recursively.
rmkdir($dir);
=cut
sub
rmkdir(){
my
$self
=
shift
;
my
$path
=
shift
;
my
$force
=
shift
;
if
(
$path
){
$path
=~ s!^\s+|\s+$!!gs;
if
(
$path
=~ m![^/\.]!){
my
$target
=
''
;
if
(
$path
=~ s!^([\./]+)!!){
$target
=$1;
}
lib/BDB/Wrapper.pm view on Meta::CPAN
15721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
'bdb'
=>
$bdb
,
'transaction'
=>
$transaction
});
OR
get_bdb_home(
$bdb
);
=cut
sub clear_bdb_home(){
my $self = shift;
my $op = shift;
my $bdb = $op->{'bdb'};
my $home_dir=$self->get_bdb_home({'bdb'=>$bdb});
# Prevent OS command injection
}
sub get_bdb_home(){
my $self=shift;
my $op=shift;
my $bdb='';
my $transaction=undef;
my $lock_root=$self->{'lock_root'};
if($op && ref($op) eq 'HASH'){
$bdb=$op->{'bdb'} || return;
if(exists($op->{'transaction'})){
$transaction=$op->{'transaction'};
}
lib/BDB/Wrapper.pm view on Meta::CPAN
162816291630163116321633163416351636163716381639164016411642164316441645164616471648
'bdb'
=>
$bdb
,
'transaction'
=> 0==
undef
or
$transaction_root_dir
});
OR
clear_bdb_home(
$bdb
);
=cut
sub clear_bdb_home(){
my $self=shift;
my $op=shift;
my $bdb='';
my $transaction=undef;
my $lock_root=$self->{'lock_root'};
if($op && ref($op) eq 'HASH'){
$bdb=$op->{'bdb'} || return;
if(exists($op->{'transaction'})){
$transaction=$op->{'transaction'};
}
lib/BDB/Wrapper.pm view on Meta::CPAN
168716881689169016911692169316941695169616971698169917001701170217031704170517061707
'msg'
=>
$error_message
,
'error_log_file'
=>
$error_log_file
});
OR
record_error(
$error_msg
)
=cut
sub record_error(){
my $self=shift;
my $op=shift || return;
my $msg='';
my $error_log_file='';
if($op && ref($op) eq 'HASH'){
$msg=$op->{'msg'};
$error_log_file=$op->{'error_log_file'};
}
else{
( run in 0.287 second using v1.01-cache-2.11-cpan-cba739cd03b )