X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;h=ca4f974104f0ce72cd3339b2ab55491f82bd306a;hb=53e0f67ff7d0877b2d64b4047992a10e17b584b9;hp=2866e46d4920dc2f862bf48928d838e25ce95a94;hpb=dcc3047078dcaa00bfa8580f12bdbf5ae5c16ff1;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 2866e46..ca4f974 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -13,10 +13,16 @@ use Catalyst::Utils; use Catalyst::Exception; use Path::Class qw/dir file/; use File::ShareDir qw/dist_dir/; +use File::HomeDir; +use Path::Resolver::Resolver::Mux::Ordered; +use Path::Resolver::Resolver::FileSystem; use namespace::autoclean; with 'MooseX::Emulate::Class::Accessor::Fast'; +# Change Catalyst/Devel.pm also +our $VERSION = '1.23'; + my %cache; =head1 NAME @@ -29,21 +35,58 @@ Catalyst::Helper - Bootstrap a Catalyst application =cut +# Return the (cached) path resolver +{ + my $resolver; + + sub get_resolver { + my $self = shift; + + # Avoid typing this over and over + my $fs_path = sub { + Path::Resolver::Resolver::FileSystem->new({ root => shift }) + }; + + unless ($resolver) { + my @resolvers; + # Search path: first try the environment variable + if (exists $ENV{CATALYST_DEVEL_SHAREDIR}) { + push @resolvers, $fs_path->($ENV{CATALYST_DEVEL_SHAREDIR}); + } + # Then the application's "helper" directory + if (exists $self->{base}) { + push @resolvers, $fs_path->(dir($self->{base}, "helper")); + } + # Then ~/.catalyst/helper + push @resolvers, $fs_path->( + dir(File::HomeDir->my_home, ".catalyst", "helper") + ); + # Finally the Catalyst default + if (-d "inc/.author" && -f "lib/Catalyst/Helper.pm" + ) { # Can't use sharedir if we're in a checkout + # this feels horrible, better ideas? + push @resolvers, $fs_path->('share'); + } + else { + push @resolvers, $fs_path->(dist_dir('Catalyst-Devel')); + } + + $resolver = Path::Resolver::Resolver::Mux::Ordered->new({ + resolvers => \@resolvers + }); + } + + return $resolver; + } +} + sub get_sharedir_file { my ($self, @filename) = @_; - my $dist_dir; - if (-d "inc/.author" && -f "lib/Catalyst/Helper.pm" - ) { # Can't use sharedir if we're in a checkout - # this feels horrible, better ideas? - $dist_dir = 'share'; - } - else { - $dist_dir = dist_dir('Catalyst-Devel'); - } - my $file = file( $dist_dir, @filename); - Carp::confess("Cannot find $file") unless -r $file; - my $contents = $file->slurp; - return $contents; + + my $filepath = file(@filename); + my $file = $self->get_resolver->entity_at("$filepath") # doesn't like object + or Carp::confess("Cannot find $filepath"); + return $file->content; } # Do not touch this method, *EVER*, it is needed for back compat. @@ -700,4 +743,3 @@ it under the same terms as Perl itself. =cut 1; -