From: Peter Rabbitson Date: Mon, 26 Aug 2013 12:18:36 +0000 (+0200) Subject: Teach the example scripts how to find their DB from anywhere X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=15ff1933c11adf39cd09114ef0e68e94dd08701f;p=dbsrgits%2FDBIx-Class-Historic.git Teach the example scripts how to find their DB from anywhere --- diff --git a/examples/Schema/insertdb.pl b/examples/Schema/insertdb.pl index 57cf5a1..c57460e 100755 --- a/examples/Schema/insertdb.pl +++ b/examples/Schema/insertdb.pl @@ -5,7 +5,10 @@ use warnings; use MyApp::Schema; -my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); +use Path::Class 'file'; +my $db_fn = file($INC{'MyApp/Schema.pm'})->dir->parent->file('db/example.db'); + +my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn"); my @artists = (['Michael Jackson'], ['Eminem']); $schema->populate('Artist', [ diff --git a/examples/Schema/testdb.pl b/examples/Schema/testdb.pl index 3d057fd..2a1061a 100755 --- a/examples/Schema/testdb.pl +++ b/examples/Schema/testdb.pl @@ -5,9 +5,12 @@ use strict; use MyApp::Schema; -my $schema = MyApp::Schema->connect('dbi:SQLite:db/example.db'); +use Path::Class 'file'; +my $db_fn = file($INC{'MyApp/Schema.pm'})->dir->parent->file('db/example.db'); + # for other DSNs, e.g. MySql, see the perldoc for the relevant dbd # driver, e.g perldoc L. +my $schema = MyApp::Schema->connect("dbi:SQLite:$db_fn"); get_tracks_by_cd('Bad'); get_tracks_by_artist('Michael Jackson');