From 54eafb3e9d17acfd3bdd9e83728f646c1a467151 Mon Sep 17 00:00:00 2001 From: "Jeffrey T. Palmer" Date: Sun, 20 May 2012 22:07:53 -0400 Subject: [PATCH] Refactor share dir usage --- lib/Games/PuzzleCars.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/Games/PuzzleCars.pm b/lib/Games/PuzzleCars.pm index f0736e4..0ae8250 100644 --- a/lib/Games/PuzzleCars.pm +++ b/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,