From 97ff3be75cf695cf0425a38f2e19a7b87f63ab9c Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 17 Feb 2010 13:28:38 +0000 Subject: [PATCH] DBD::SQLite: added preamble to generate modules to provide bundled c source/header (for other extensions) --- Makefile.PL | 40 ++++++++++++++++++++++++++++++++++++++++ t/43_source_files.t | 23 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 t/43_source_files.t diff --git a/Makefile.PL b/Makefile.PL index 8086d06..51d5fe8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -323,6 +323,46 @@ package MY; use Config; sub postamble { + foreach my $file (qw/sqlite3.h sqlite3.c/) { + (my $pm = $file) =~ tr/./_/; + print "generating lib/DBD/SQLite/$pm.pm\n"; + open my $fh, '>', "lib/DBD/SQLite/$pm.pm" or die $!; + print $fh <<"EOT"; +package DBD::SQLite::$pm; + +use strict; +our \$CODE = do { local \$/; }; + +sub get { + my (\$class, \$file, \$out) = \@_; + my \$got; + if (\$file) { + (\$got) = \$CODE =~ m{( + /\\*+[ ]Begin[ ]file[ ]\$file[ ]\\*+ + .+? + /\\*+[ ]End[ ]of[ ]\$file[ ]\\*+/ + )}sx; + } + else { + \$got = \$CODE; + } + if (\$got && \$out) { + open my \$fh, '>', \$out or die \$!; + print \$fh \$got; + } + return \$got ? \$got : ''; +} + +1; +\__DATA__ +EOT + print $fh do { + local $/; + open my $in, '<', $file or die $!; + <$in>; + }; + } + require DBI; require DBI::DBD; eval { diff --git a/t/43_source_files.t b/t/43_source_files.t new file mode 100644 index 0000000..e40614e --- /dev/null +++ b/t/43_source_files.t @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test qw/connect_ok @CALL_FUNCS/; +use Test::More; +use Test::NoWarnings; + +plan tests => 6; + +use_ok('DBD::SQLite::sqlite3_h'); +use_ok('DBD::SQLite::sqlite3_c'); + +my $header = DBD::SQLite::sqlite3_h->get; +like $header => qr/define _SQLITE3_H_/, 'got whole file'; + +my $hwtime_h = DBD::SQLite::sqlite3_c->get('hwtime.h'); +like $hwtime_h => qr/Begin file hwtime.h/, 'has Begin file'; +unlike $hwtime_h => qr/Begin file [^h][^w]/, 'has no other Begin file';