Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to distribute an example data file in a CPAN module

by zby (Vicar)
on Feb 19, 2009 at 14:39 UTC ( [id://745065]=perlquestion: print w/replies, xml ) Need Help??

zby has asked for the wisdom of the Perl Monks concerning the following question:

Dear Brothers in Perl,

I would like to add an example SQLite database to Catalyst::Example::InstantCRUD - so that it lives up to it's name. That is I would like that instantcrud.pl when invoked without a DSN would connect to that example database and produce the appriopriate CRUD application. It might be even the database that I use in the tests - but I have no reliable way of finding it from a working script. What are my options?

  • Comment on How to distribute an example data file in a CPAN module

Replies are listed 'Best First'.
Re: How to distribute an example data file in a CPAN module
by Corion (Patriarch) on Feb 19, 2009 at 14:42 UTC

    I'd append the SQL to create that database to the script itself, in (for example) a __DATA__ section. That way, it's easily seen or modified.

      Hmmm - yeah - you are right! I was thinking about an in memory database - I think I've seen something like that but I could not figure out how to do it so I decided that I must have confused something and stopped thinking in that direction.
Re: How to distribute an example data file in a CPAN module
by jplindstrom (Monsignor) on Feb 20, 2009 at 00:58 UTC
    I think SQLite db files are binary cross platform, but possibly not across versions. I guess you'd have to check the SQLite manual for that.

    That does sound a bit fragile in any case, so the DDL might be a more solid choice.

    You can put data files next to where your module source gets installed. Find out where that is:

    package Your::Module; use Path::Class; # Return ".../site_lib/Your/Module/data/sample.sql" sub sample_db_file { file( file(__FILE__)->dir->absolute, "data", "sample.sql") . ""; }

    If you use Module::Build, you need to specify that nonstandard file extensions should be packaged, like this:

    # Build.PL $builder->add_build_element('sql');

    Not sure about the EMM or Module::Install incantations.

    So you'll need to create a .db file in a convenient (for the user) writable location. File::HomeDir might be useful for finding that location.

    /J

      Thanks! Although I decided to put the SQL into __DATA__ - but once it grows I'll remember your solution :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://745065]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-05-26 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found