1 package Catalyst::Helper::AppGen;
4 use namespace::autoclean;
5 use Moose::Util::TypeConstraints;
6 use namespace::autoclean;
8 extends { 'Catalyst::Helper' };
13 traits => [qw(Getopt)],
20 traits => [qw(Getopt)],
25 my ( $self, $name ) = @_;
27 # Needs to be here for PAR
30 if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
31 warn "Error: Invalid application name.\n";
34 $self->{name } = $name;
35 $self->{dir } = $name;
36 $self->{dir } =~ s/\:\:/-/g;
37 $self->{script } = File::Spec->catdir( $self->{dir}, 'script' );
38 $self->{appprefix } = Catalyst::Utils::appprefix($name);
39 $self->{appenv } = Catalyst::Utils::class2env($name);
40 $self->{startperl } = -r '/usr/bin/env'
41 ? '#!/usr/bin/env perl'
42 : "#!$Config{perlpath} -w";
43 $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4;
44 $self->{catalyst_version} = $Catalyst::VERSION;
45 $self->{author } = $self->{author} = $ENV{'AUTHOR'}
46 || eval { @{ [ getpwuid($<) ] }[6] }
47 || 'Catalyst developer';
49 my $gen_scripts = ( $self->{makefile} ) ? 0 : 1;
50 my $gen_makefile = ( $self->{scripts} ) ? 0 : 1;
51 my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1;
73 $self->_mk_information;
82 $self->{author} = $self->{author} = $ENV{'AUTHOR'}
83 || eval { @{ [ getpwuid($<) ] }[6] }
85 $self->{base} ||= File::Spec->catdir( $FindBin::Bin, '..' );
86 unless ( $_[0] =~ /^(?:model|view|controller)$/i ) {
89 my $class = "Catalyst::Helper::$helper";
90 eval "require $class";
93 Catalyst::Exception->throw(
94 message => qq/Couldn't load helper "$class", "$@"/ );
97 if ( $class->can('mk_stuff') ) {
98 return 1 unless $class->mk_stuff( $self, @args );
103 my $name = shift || "Missing name for model/view/controller";
106 return 0 if $name =~ /[^\w\:]/;
108 $self->{long_type} = ucfirst $type;
109 $type = 'M' if $type =~ /model/i;
110 $type = 'V' if $type =~ /view/i;
111 $type = 'C' if $type =~ /controller/i;
112 my $appdir = File::Spec->catdir( split /\:\:/, $app );
114 File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, 'C' );
115 $type = $self->{long_type} unless -d $test_path;
116 $self->{type} = $type;
117 $self->{name} = $name;
118 $self->{class} = "$app\::$type\::$name";
122 File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type );
124 if ( $name =~ /\:/ ) {
125 my @path = split /\:\:/, $name;
127 $path = File::Spec->catdir( $path, @path );
129 $self->mk_dir($path);
130 $file = File::Spec->catfile( $path, "$file.pm" );
131 $self->{file} = $file;
135 return 1 unless $self->_mk_compclass;