| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package DBD::SQLite::BundledExtensions; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Provides a number of C extensions for DBD::SQLite and some functions to help load them | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 28451 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 2022 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 8 | use File::Find; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 46 |  | 
| 8 | 1 |  |  | 1 |  | 7 | use File::Spec; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 268 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our $VERSION="0.002"; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | for my $ext (qw/spellfix csv ieee754 nextchar percentile series totype wholenumber eval/) { | 
| 13 | 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 |  | 
| 14 |  |  |  |  |  |  | } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub _load_extension { | 
| 17 | 9 |  |  | 9 |  | 17633 | my ($self, $dbh, $extension_name) = @_; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 9 |  |  |  |  | 22 | my $file = $self->_locate_extension_library($extension_name); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 9 |  |  |  |  | 62 | $dbh->sqlite_enable_load_extension(1); | 
| 22 | 9 | 50 |  |  |  | 53 | $dbh->do("select load_extension(?)", {}, $file) | 
| 23 |  |  |  |  |  |  | or die "Cannot load '$extension_name' extension: " . $dbh->errstr(); | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub _locate_extension_library { | 
| 27 | 9 |  |  | 9 |  | 20 | my ($self, $extension_name) = @_; | 
| 28 | 9 |  |  |  |  | 15 | my $sofile; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | my $wanted = sub { | 
| 31 | 107 |  |  | 107 |  | 281 | my $file = $File::Find::name; | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 107 | 100 |  |  |  | 4972 | if ($file =~ m/DBD-SQLite-BundledExtensions.\Q$extension_name\E\.(so|dll|dylib)$/i){ | 
| 34 | 9 |  |  |  |  | 22 | $sofile = $file; | 
| 35 | 9 |  |  |  |  | 133 | die; # bail out on the first one we find, this might need to be more configurable | 
| 36 |  |  |  |  |  |  | } | 
| 37 | 9 |  |  |  |  | 50 | }; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 9 |  |  |  |  | 19 | eval {find({wanted => $wanted, no_chdir => 1}, @INC);}; | 
|  | 9 |  |  |  |  | 653 |  | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 9 | 50 |  |  |  | 35 | if ($sofile) { | 
| 42 | 9 |  |  |  |  | 137 | $sofile = File::Spec->rel2abs($sofile); # Make it an absolute path, if it isn't already.  Aids in portability | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 9 |  |  |  |  | 51 | return $sofile; | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | 1; | 
| 49 |  |  |  |  |  |  | __END__ |