Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor share dir usage

  • Loading branch information...
commit 54eafb3e9d17acfd3bdd9e83728f646c1a467151 1 parent 324f11b
@jtpalmer authored
Showing with 16 additions and 2 deletions.
  1. +16 −2 lib/Games/PuzzleCars.pm
View
18 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;
@@ -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 => (
@@ -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,
Please sign in to comment.
Something went wrong with that request. Please try again.