Permalink
Browse files

Refactored share-directory.

  • Loading branch information...
1 parent e8ada2a commit cc4acbe5930ab61e68c8b0b7eec67d83a1655b65 @jtpalmer committed Aug 21, 2010
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
@@ -3,13 +3,32 @@ 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;
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
@@ -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',

0 comments on commit cc4acbe

Please sign in to comment.