Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored share-directory.

  • Loading branch information...
commit cc4acbe5930ab61e68c8b0b7eec67d83a1655b65 1 parent e8ada2a
@jtpalmer authored
Showing with 21 additions and 9 deletions.
  1. +20 −8 lib/Games/Maze/SDL.pm
  2. +1 −1  lib/Games/Maze/SDL/View/Player.pm
View
28 lib/Games/Maze/SDL.pm
@@ -3,6 +3,7 @@ package Games::Maze::SDL;
# ABSTRACT: Maze game; using SDL!
use Moose;
+use MooseX::ClassAttribute;
use Games::Maze::SDL::Model::Maze;
use Games::Maze::SDL::Model::Player;
use Games::Maze::SDL::View::Maze;
@@ -10,6 +11,24 @@ use Games::Maze::SDL::View::Player;
use Games::Maze::SDL::Controller;
use FindBin;
use Path::Class;
+use File::ShareDir;
+
+class_has 'share_dir' => (
+ is => 'ro',
+ lazy_build => 1,
+ init_arg => undef,
+);
+
+sub _build_share_dir {
+ my $root = Path::Class::Dir->new( $FindBin::Bin, '..' );
+ if ( -f $root->file('dist.ini') ) {
+ return $root->subdir('share');
+ }
+ else {
+ return Path::Class::Dir->new(
+ File::ShareDir::dist_dir('Games-Maze-SDL') );
+ }
+}
sub run {
my ( $self, %options ) = @_;
@@ -62,13 +81,6 @@ sub run {
$controller->run;
}
-sub sharedir {
-
- # TODO
- my $root = Path::Class::Dir->new( $FindBin::Bin, '..' );
- return $root->subdir('share');
-}
-
no Moose;
__PACKAGE__->meta->make_immutable;
@@ -80,7 +92,7 @@ __END__
use Games::Maze::SDL;
- Games::Maze::SDL->run( %options );
+ Games::Maze::SDL->new->run( %options );
=head1 SEE ALSO
View
2  lib/Games/Maze/SDL/View/Player.pm
@@ -34,7 +34,7 @@ sub _build_sprite {
my ($self) = @_;
my $sprite = SDLx::Sprite::Animated->new(
- image => Games::Maze::SDL->sharedir->file('hero.png'),
+ image => Games::Maze::SDL->share_dir->file('hero.png'),
rect => SDL::Rect->new( 0, 0, 24, 24 ),
ticks_per_frame => 10,
type => 'reverse',
Please sign in to comment.
Something went wrong with that request. Please try again.