X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FHelper.pm;fp=lib%2FCatalyst%2FHelper.pm;h=ca4f974104f0ce72cd3339b2ab55491f82bd306a;hb=53e0f67ff7d0877b2d64b4047992a10e17b584b9;hp=86ba60f7e2de03a4effc222ace20d3561a2893a1;hpb=d2985b9508b24b36c6800baa69214ed16817353b;p=catagits%2FCatalyst-Devel.git diff --git a/lib/Catalyst/Helper.pm b/lib/Catalyst/Helper.pm index 86ba60f..ca4f974 100644 --- a/lib/Catalyst/Helper.pm +++ b/lib/Catalyst/Helper.pm @@ -13,6 +13,9 @@ 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'; @@ -32,33 +35,58 @@ Catalyst::Helper - Bootstrap a Catalyst application =cut -sub get_sharedir_file { - my ($self, @filename) = @_; +# Return the (cached) path resolver +{ + my $resolver; - my @try_dirs; - if (exists $self->{base}) { - push @try_dirs, $self->{base}; - } - if (exists $ENV{CATALYST_DEVEL_SHAREDIR}) { - push @try_dirs, $ENV{CATALYST_DEVEL_SHAREDIR} - } - 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 @try_dirs, 'share'; - } - else { - push @try_dirs, dist_dir('Catalyst-Devel'); - } + 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')); + } - my $file; - foreach my $dist_dir (@try_dirs) { - $file = file( $dist_dir, @filename); - last if -r $file; + $resolver = Path::Resolver::Resolver::Mux::Ordered->new({ + resolvers => \@resolvers + }); + } + + return $resolver; } - Carp::confess("Cannot find $file") unless -r $file; - my $contents = $file->slurp; - return $contents; +} + +sub get_sharedir_file { + my ($self, @filename) = @_; + + 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. @@ -715,4 +743,3 @@ it under the same terms as Perl itself. =cut 1; -