File Coverage

blib/lib/Paranoid/BerkeleyDB/Core.pm
Criterion Covered Total %
statement 16 18 88.8
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 24 91.6


line stmt bran cond sub pod time code
1             # Paranoid::BerkeleyDB::Db -- Paranoid BerkeleyDB Core
2             #
3             # (c) 2005 - 2015, Arthur Corliss
4             #
5             # $Id: lib/Paranoid/BerkeleyDB/Core.pm, 2.02 2016/06/21 19:51:06 acorliss Exp $
6             #
7             # This software is licensed under the same terms as Perl, itself.
8             # Please see http://dev.perl.org/licenses/ for more information.
9             #
10             #####################################################################
11              
12             #####################################################################
13             #
14             # Dbironment definitions
15             #
16             #####################################################################
17              
18             package Paranoid::BerkeleyDB::Core;
19              
20 2     2   8 use strict;
  2         2  
  2         47  
21 2     2   6 use warnings;
  2         2  
  2         42  
22 2     2   10 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  2         2  
  2         88  
23 2     2   10 use Paranoid;
  2         2  
  2         108  
24 2     2   6 use Paranoid::Debug qw(:all);
  2         2  
  2         208  
25 2     2   1480 use BerkeleyDB;
  0            
  0            
26             use Exporter;
27              
28             ($VERSION) = ( q$Revision: 2.02 $ =~ /(\d+(?:\.\d+)+)/sm );
29              
30             @ISA = qw(Exporter);
31              
32             @EXPORT = qw(_addBlacklist _installScreener);
33             @EXPORT_OK = @EXPORT;
34              
35             #####################################################################
36             #
37             # module code follows
38             #
39             #####################################################################
40              
41             {
42             our @blacklist;
43              
44             sub _addBlacklist {
45             my @b = @_;
46              
47             push @blacklist, @b;
48              
49             return 1;
50             }
51              
52             our @pkgs = qw(BerkeleyDB BerkeleyDB::Env BerkeleyDB::Hash
53             BerkeleyDB::Btree BerkeleyDB::Heap BerkeleyDB::Recno
54             BerkeleyDB::Queue BerkeleyDB::Unknown BerkeleyDB::_tiedHash
55             BerkeleyDB::_tiedArray BerkeleyDB::Common BerkeleyDB::Cursor
56             BerkeleyDB::TxnMgr BerkeleyDB::Txn );
57              
58             sub _chkBlacklist {
59              
60             # Purpose: Calls the original DESTROY method if the object
61             # isn't on the blacklist
62             # Returns: Boolean;
63             # Usage: $rv = $obj->DESTROY;
64              
65             my $obj = shift;
66             my $rv = 1;
67             my $u;
68              
69             pdebug( 'looking for %s in %s', PDLEVEL4, $obj, @blacklist );
70             pIn();
71              
72             # Filter out undef entries
73             # @blacklist = grep { defined $_ } @blacklist;
74             $u = grep { !defined $_ } @blacklist;
75              
76             if ( defined $obj and !$u ) {
77             if ( grep { $obj == $_ } @blacklist ) {
78             pdebug( 'matched -- skipping DESTROY phase', PDLEVEL4 );
79             } else {
80             pdebug( 'no match -- executing DESTROY phase', PDLEVEL4 );
81             $rv = $obj->_PDBDESTROY;
82             }
83             } elsif ($u) {
84             pdebug( 'undefs in blacklist -- assume process exit', PDLEVEL4 );
85             #$rv = $obj->_PDBDESTROY;
86             }
87              
88             pOut();
89             pdebug( 'leaving w/rv: %s', PDLEVEL4, $rv );
90              
91             return $rv;
92             }
93              
94             sub _installScreener {
95              
96             # Purpose: Installs filter wrappers for DESTROY methods
97             # Returns: Boolean
98             # Usage: $rv = _installScreener();
99              
100             my ( $pkg, $tfqm, $dfqm, $code1, $code2 );
101              
102             pdebug( 'entering', PDLEVEL4 );
103             pIn();
104              
105             $code2 = \&_chkBlacklist;
106              
107             foreach $pkg (@pkgs) {
108             {
109              
110             # Wrap BerkeleyDB's DESTROY methods with
111             # a filter sub
112              
113             no strict 'refs';
114             no warnings qw(redefine prototype);
115              
116             $tfqm = $pkg . '::DESTROY';
117             $dfqm = $pkg . '::_PDBDESTROY';
118             $code1 = *{$tfqm}{CODE};
119              
120             # Make sure we haven't already done this
121             next if !defined $code1 or $code1 == $code2;
122              
123             pdebug( 'installing filter for %s', PDLEVEL4, $tfqm );
124              
125             # Make the change
126             *{$tfqm} = $code2;
127             *{$dfqm} = $code1;
128             }
129             }
130              
131             pOut();
132             pdebug( 'leaving w/rv: 1', PDLEVEL4 );
133              
134             return 1;
135             }
136             }
137              
138             1;
139              
140             __END__