File Coverage

blib/lib/DBD/SQLite/BundledExtensions.pm
Criterion Covered Total %
statement 25 43 58.1
branch 4 6 66.6
condition n/a
subroutine 6 15 40.0
pod 9 9 100.0
total 44 73 60.2


line stmt bran cond sub pod time code
1             package DBD::SQLite::BundledExtensions;
2              
3 1     1   20860 use strict;
  1         2  
  1         22  
4              
5 1     1   3 use File::Find;
  1         1  
  1         34  
6 1     1   3 use File::Spec;
  1         4  
  1         191  
7              
8             for my $ext (qw/spellfix csv ieee754 nextchar percentile series totype wholenumber eval/) {
9 0     0 1 0 eval "sub load_${ext} {my (\$self, \$dbh)=\@_; \$self->_load_extension(\$dbh, '${ext}')}";
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0     0 1 0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
10             }
11              
12             sub _load_extension {
13 9     9   12226 my ($self, $dbh, $extension_name) = @_;
14              
15 9         19 my $file = $self->_locate_extension_library($extension_name);
16              
17 9         38 $dbh->sqlite_enable_load_extension(1);
18 9 50       33 $dbh->do("select load_extension(?)", {}, $file)
19             or die "Cannot load '$extension_name' extension: " . $dbh->errstr();
20             }
21              
22             sub _locate_extension_library {
23 9     9   10 my ($self, $extension_name) = @_;
24 9         6 my $sofile;
25              
26             my $wanted = sub {
27 206     206   156 my $file = $File::Find::name;
28              
29 206 100       6607 if ($file =~ m/DBD-SQLite-BundledExtensions.\Q$extension_name\E\.(so|dll|dylib)$/i){
30 9         7 $sofile = $file;
31 9         110 die; # bail out on the first one we find, this might need to be more configurable
32             }
33 9         37 };
34              
35 9         10 eval {find({wanted => $wanted, no_chdir => 1}, @INC);};
  9         518  
36              
37 9 50       21 if ($sofile) {
38 9         94 $sofile = File::Spec->rel2abs($sofile); # Make it an absolute path, if it isn't already. Aids in portability
39             }
40              
41 9         34 return $sofile;
42             }
43              
44             1;
45             __END__