package Catalyst::Helper;
-
-use strict;
-use warnings;
-use base 'Class::Accessor::Fast';
+use Moose;
use Config;
use File::Spec;
use File::Path;
use Catalyst::Exception;
use Path::Class qw/dir file/;
use File::ShareDir qw/dist_dir/;
-use Moose;
use aliased 'Path::Class::Dir';
-
+use namespace::autoclean;
my %cache;
sub get_sharedir_file {
my ($self, @filename) = @_;
my $dist_dir;
- if (-d "inc/.author") { # Can't use sharedir if we're in a checkout
- # this feels horrible, better ideas?
+ 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 {
$file .= '.new';
}
}
+
if ( my $f = IO::File->new("> $file") ) {
binmode $f;
print $f $content;
# Do not touch this method, *EVER*, it is needed for back compat.
## addendum: we had to split this method so we could have backwards
-## compatability. otherwise, we'd have no way to pass stuff from __DATA__
+## compatability. otherwise, we'd have no way to pass stuff from __DATA__
sub render_file {
my ( $self, $file, $path, $vars ) = @_;
sub _mk_compclass {
my $self = shift;
my $file = $self->{file};
- return $self->render_sharedir_file( 'myapp_compclass.pl.tt', "$file" );
+ return $self->render_sharedir_file( 'lib', 'Helper', 'compclass.tt', "$file" );
}
sub _mk_comptest {
my $self = shift;
my $test = $self->{test};
- $self->render_sharedir_file( 'comptest.tt', "$test" ); ## wtf do i rename this to?
+ $self->render_sharedir_file( 't', 'comptest.tt', "$test" ); ## wtf do i rename this to?
}
sub _mk_images {
}
-## this is so you don't have to do make install after every change to test
-sub _find_share_dir {
- my ($self, $args) = @_;
- my $share_name = $self->name;
- if ($share_name =~ s!^/(.*?)/!!) {
- my $dist = $1;
- $args->{share_base_dir} = eval {
- Dir->new(File::ShareDir::dist_dir($dist))
- ->subdir('share');
- };
- if ($@) {
- # not installed
- my $file = __FILE__;
- my $dir = Dir->new(dirname($file));
- my $share_base;
- while ($dir->parent) {
- if (-d $dir->subdir('share') && -d $dir->subdir('share')->subdir('root')) {
- $share_base = $dir->subdir('share')->subdir('root');
- last;
- }
- $dir = $dir->parent;
- }
- confess "could not find sharebase by recursion. ended up at $dir, from $file"
- unless $share_base;
- $args->{share_base_dir} = $share_base;
- }
- }
- my $base = $args->{share_base_dir}->subdir($share_name);
- confess "No such share base directory ${base}"
- unless -d $base;
- $self->share_dir($base);
-};
-
-
-
=head1 DESCRIPTION
This module is used by B<catalyst.pl> to create a set of scripts for a