quick question: my new Geo::Postcode - name currently subject of debate - comes with sample data in the form of a SQLite file. I can't just distribute the data file, because of binary incompatibilities (endianness, I suppose), so the data is distributed in a csv file and copied into SQLite during installation.

My question: what's the best way to do that, and at what stage?

At the moment I've got the data-writing code in Makefile.PL, wrapped in an eval so that if it fails the process will continue, Makemaker will notice the missing module and CPAN.pm will go off and install the requirements.

Doesn't really work, though. Having gone away to install the requirements, CPAN will not run the Makefile.PL again, so the data file never gets written.

And anyway, as David Cantrell has pointed out, the correct place to write the database file would be between make and make test. I have no idea how to do that. I could just hide it in the first test, of course. but do people always run make test? And anyway it would be underhanded and wrong. Bah.

any help - or good examples to copy - would be much appreciated.

thanks,
will

here's the current Makefile.PL, by the way:

#!/usr/bin/perl -w # -*- perl +-*- use strict; use lib qw( ./lib ); use ExtUtils::MakeMaker; $|++; my $csvdata = './useful/postcodes.csv'; my $datafile = './lib/Geo/Postcode/postcodes.db'; my $tablename = 'postcodes'; create_sqlite_file() unless -e $datafile; WriteMakefile( NAME => 'Geo::Postcode', VERSION_FROM => 'lib/Geo/Postcode.pm', PREREQ_PM => { 'DBD::SQLite' => 0 }, ($] >= 5.005 ? (ABSTRACT_FROM => 'lib/Geo/Postcode.pm', AUTHOR => 'william ro +ss <wross@cpan.org>') : () ), clean => { 'FILES' => $datafile }, ); sub create_sqlite_file { print "Creating sample data file.\n"; my $dbh; eval { use DBI; $dbh = DBI->connect("dbi:SQLite:dbname=$datafile","",""); }; if ($@) { print "Connection failed. Is DBD::SQLite installed? Makemaker +will tell us:\n"; return; } open( INPUT, $csvdata) || die("can't open file $csvdata: $!"); my @cols = split(',',<INPUT>); my $columns = join(', ', map { "$_ varchar(255)" } grep { $_ ne 'p +ostcode' } @cols); $dbh->do("create table $tablename (postcode varchar(12) primary ke +y, $columns);"); my $counter; my $insert = "INSERT INTO $tablename( " . join(',',@cols) . " ) va +lues ( " . join(',', map { '?' } @cols) . ")"; my $sth = $dbh->prepare($insert); while (<INPUT>) { chomp; my @data = split(/,/); $sth->execute( @data ); $counter++; print "." unless $counter % 40; } $sth->finish; $dbh->disconnect; print "done.\n$counter points imported into sample data set.\n\n"; }

In reply to cpan module with binary data: when to build? by thpfft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.