BDB-Wrapper

 view release on metacpan or  search on metacpan

lib/BDB/Wrapper.pm  view on Meta::CPAN

734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
  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

810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
    '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

892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
}
 
=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

948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
  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

1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
  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

1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
  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

1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
  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 use_env 1, you can use environment for this method.
 
=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

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
}
 
=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

1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
    '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

1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
    '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

1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
    '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 )