1 package Catalyst::Helper::ComponentGen;
4 use Moose::Util::TypeConstraints;
5 use MooseX::Types -declare [qw/ TestDir LongComponentType ValidComponentName /];
6 use namespace::autoclean;
8 extends { 'Catalyst::Helper' };
10 # subtypes and coercions
11 # validate test dir, component name
12 # make the check in $self->{test_dir} be less fucking stupid
19 has 'long_comp_type' => (
21 isa => LongComponentType,
22 initializer => 'long_type',
25 has 'component_name' => (
27 isa => ValidComponentName,
28 initializer => 'comp_name',
32 $self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' );
33 $self->{test} = $self->next_test;
37 my $comp = $self->{long_type};
38 my $class = "Catalyst::Helper::$comp\::$helper";
39 eval "require $class";
42 Catalyst::Exception->throw(
43 message => qq/Couldn't load helper "$class", "$@"/ );
46 ## NO TOUCHY ###############################################################
47 if ( $class->can('mk_compclass') ) {
48 return 1 unless $class->mk_compclass( $self, @args );
50 else { return 1 unless $self->_mk_compclass }
52 if ( $class->can('mk_comptest') ) {
53 $class->mk_comptest( $self, @args );
55 else { $self->_mk_comptest }
56 ## END NO TOUCHY ###########################################################
63 $self->{author} = $self->{author} = $ENV{'AUTHOR'}
64 || eval { @{ [ getpwuid($<) ] }[6] }
66 $self->{base} ||= File::Spec->catdir( $FindBin::Bin, '..' );
67 unless ( $_[0] =~ /^(?:model|view|controller)$/i ) {
70 my $class = "Catalyst::Helper::$helper";
71 eval "require $class";
74 Catalyst::Exception->throw(
75 message => qq/Couldn't load helper "$class", "$@"/ );
78 if ( $class->can('mk_stuff') ) {
79 return 1 unless $class->mk_stuff( $self, @args );
84 my $name = shift || "Missing name for model/view/controller";
87 return 0 if $name =~ /[^\w\:]/;
89 $self->{long_type} = ucfirst $type;
90 $type = 'M' if $type =~ /model/i;
91 $type = 'V' if $type =~ /view/i;
92 $type = 'C' if $type =~ /controller/i;
93 my $appdir = File::Spec->catdir( split /\:\:/, $app );
95 File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, 'C' );
96 $type = $self->{long_type} unless -d $test_path;
97 $self->{type} = $type;
98 $self->{name} = $name;
99 $self->{class} = "$app\::$type\::$name";
103 File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type );
105 if ( $name =~ /\:/ ) {
106 my @path = split /\:\:/, $name;
108 $path = File::Spec->catdir( $path, @path );
110 $self->mk_dir($path);
111 $file = File::Spec->catfile( $path, "$file.pm" );
112 $self->{file} = $file;
116 return 1 unless $self->_mk_compclass;