Skip to content

Commit

Permalink
resolve real share_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Oct 3, 2013
1 parent eea9267 commit 579048b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ requires 'Amon2::Web';
requires 'Amon2::Web::Dispatcher::Lite';
requires 'Capture::Tiny';
requires 'File::Find::Rule';
requires 'File::ShareDir';
requires 'LWP::UserAgent';
requires 'Locale::Maketext::Extract';
requires 'Plack::Builder';
Expand Down
13 changes: 11 additions & 2 deletions lib/Ukigumo/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use 5.010001;
use parent qw(Amon2);
use Carp;
use DBI;
use File::ShareDir;
use File::Spec;

use Ukigumo::Server::DB;
Expand Down Expand Up @@ -65,8 +66,16 @@ sub setup_schema {
my $self = shift;
my $f = lc $self->dbdriver . '.sql';
my $fname = File::Spec->catfile($self->share_dir , 'sql', $f);
open my $fh, '<', $fname or die "Cannot open $fname: $!";
my $schema = do { local $/; <$fh> };
unless (-f $fname) {
# Resolve real share_dir. User himself might create 'share/' dir in current directory.
my $real_share = File::ShareDir::dist_dir('Ukigumo-Server');
$fname = File::Spec->catfile($real_share, 'sql', $f);
}
my $schema = do {
local $/;
open my $fh, '<', $fname or die "Cannot open $fname: $!";
<$fh>
};
for my $code (split /;/, $schema) {
next if $code =~ /^$/;
$self->dbh->do( $code );
Expand Down

0 comments on commit 579048b

Please sign in to comment.