use Moose;
use Config;
use File::Spec;
+use File::Spec::Unix;
use File::Path;
use FindBin;
use IO::File;
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 Path::Resolver::Resolver::DistDir;
use namespace::autoclean;
+with 'MooseX::Emulate::Class::Accessor::Fast';
+
+# Change Catalyst/Devel.pm also
+our $VERSION = '1.23';
+
my %cache;
=head1 NAME
=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, Path::Resolver::Resolver::DistDir->new({
+ dist_name => "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.
$self->{startperl } = -r '/usr/bin/env'
? '#!/usr/bin/env perl'
: "#!$Config{perlpath} -w";
- $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 34;
+ $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN;
$self->{catalyst_version} = $Catalyst::VERSION;
$self->{author } = $self->{author} = $ENV{'AUTHOR'}
|| eval { @{ [ getpwuid($<) ] }[6] }
message => qq/Couldn't load helper "$class", "$@"/ );
}
- ## must be left for back compat! ###################################
if ( $class->can('mk_compclass') ) {
return 1 unless $class->mk_compclass( $self, @args );
}
- else { return 1 unless $self->_mk_compclass }
+ else {
+ return 1 unless $self->_mk_compclass
+ }
if ( $class->can('mk_comptest') ) {
$class->mk_comptest( $self, @args );
}
- else { $self->_mk_comptest }
- ####################################################################
+ else {
+ $self->_mk_comptest
+ }
}
# Fallback
This method is called by L<create.pl> to make new components
for your application.
-=head3 mk_dir ($path)
+=head2 mk_dir ($path)
Surprisingly, this function makes a directory.
=cut
1;
-