Skip to content

Commit

Permalink
Refactor share dir usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer committed May 21, 2012
1 parent 324f11b commit 54eafb3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/Games/PuzzleCars.pm
@@ -1,7 +1,11 @@
package Games::PuzzleCars;
use strict;
use warnings;
use Mouse;
use FindBin qw( $Bin );
use namespace::clean -except => 'meta';
use FindBin;
use File::Spec;
use File::ShareDir;
use SDL 2.500;
use SDLx::App;
use SDLx::Surface;
Expand All @@ -12,7 +16,7 @@ use Games::PuzzleCars::Car;
has share_dir => (
is => 'ro',
isa => 'Str',
default => sub { File::Spec->catdir( $Bin, 'share' ) },
builder => '_build_share_dir',
);

has app => (
Expand Down Expand Up @@ -82,6 +86,16 @@ has _surfaces => (
builder => '_build_surfaces',
);

sub _build_share_dir {
my $root = File::Spec->catdir( $FindBin::Bin, '..' );
if ( -f File::Spec->catfile( $root, 'dist.ini' ) ) {
return File::Spec->catdir( $root, 'share' );
}
else {
return File::ShareDir::dist_dir('Games-PuzzleCars');
}
}

sub _build_app {
return SDLx::App->new(
w => 800,
Expand Down

0 comments on commit 54eafb3

Please sign in to comment.