[Catalyst-commits] r11036 - in
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst: . Helper
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Wed Aug 5 20:08:33 GMT 2009
Author: dhoss
Date: 2009-08-05 20:08:32 +0000 (Wed, 05 Aug 2009)
New Revision: 11036
Added:
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm
Modified:
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm
Log:
moved this stuff to the right place
Added: Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm (rev 0)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm 2009-08-05 20:08:32 UTC (rev 11036)
@@ -0,0 +1,142 @@
+package Catalyst::Helper::AppGen;
+
+use Moose;
+use namespace::autoclean;
+use Moose::Util::TypeConstraints;
+use namespace::autoclean;
+
+extends { 'Catalyst::Helper' };
+
+has name => (
+ is => 'ro',
+ isa => Str,
+ traits => [qw(Getopt)],
+ cmd_aliases => 'n',
+);
+
+has dir => (
+ is => 'ro',
+ isa => Str,
+ traits => [qw(Getopt)],
+ cmd_aliases => 'n',
+);
+
+sub mk_app {
+ my ( $self, $name ) = @_;
+
+ # Needs to be here for PAR
+ require Catalyst;
+
+ if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
+ warn "Error: Invalid application name.\n";
+ return 0;
+ }
+ $self->{name } = $name;
+ $self->{dir } = $name;
+ $self->{dir } =~ s/\:\:/-/g;
+ $self->{script } = File::Spec->catdir( $self->{dir}, 'script' );
+ $self->{appprefix } = Catalyst::Utils::appprefix($name);
+ $self->{appenv } = Catalyst::Utils::class2env($name);
+ $self->{startperl } = -r '/usr/bin/env'
+ ? '#!/usr/bin/env perl'
+ : "#!$Config{perlpath} -w";
+ $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4;
+ $self->{catalyst_version} = $Catalyst::VERSION;
+ $self->{author } = $self->{author} = $ENV{'AUTHOR'}
+ || eval { @{ [ getpwuid($<) ] }[6] }
+ || 'Catalyst developer';
+
+ my $gen_scripts = ( $self->{makefile} ) ? 0 : 1;
+ my $gen_makefile = ( $self->{scripts} ) ? 0 : 1;
+ my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1;
+
+ if ($gen_app) {
+ $self->_mk_dirs;
+ $self->_mk_config;
+ $self->_mk_appclass;
+ $self->_mk_rootclass;
+ $self->_mk_readme;
+ $self->_mk_changes;
+ $self->_mk_apptest;
+ $self->_mk_images;
+ $self->_mk_favicon;
+ }
+ if ($gen_makefile) {
+ $self->_mk_makefile;
+ }
+ if ($gen_scripts) {
+ $self->_mk_cgi;
+ $self->_mk_fastcgi;
+ $self->_mk_server;
+ $self->_mk_test;
+ $self->_mk_create;
+ $self->_mk_information;
+ }
+ return $self->{dir};
+}
+
+sub mk_component {
+ my $self = shift;
+ my $app = shift;
+ $self->{app} = $app;
+ $self->{author} = $self->{author} = $ENV{'AUTHOR'}
+ || eval { @{ [ getpwuid($<) ] }[6] }
+ || 'A clever guy';
+ $self->{base} ||= File::Spec->catdir( $FindBin::Bin, '..' );
+ unless ( $_[0] =~ /^(?:model|view|controller)$/i ) {
+ my $helper = shift;
+ my @args = @_;
+ my $class = "Catalyst::Helper::$helper";
+ eval "require $class";
+
+ if ($@) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load helper "$class", "$@"/ );
+ }
+
+ if ( $class->can('mk_stuff') ) {
+ return 1 unless $class->mk_stuff( $self, @args );
+ }
+ }
+ else {
+ my $type = shift;
+ my $name = shift || "Missing name for model/view/controller";
+ my $helper = shift;
+ my @args = @_;
+ return 0 if $name =~ /[^\w\:]/;
+ $type = lc $type;
+ $self->{long_type} = ucfirst $type;
+ $type = 'M' if $type =~ /model/i;
+ $type = 'V' if $type =~ /view/i;
+ $type = 'C' if $type =~ /controller/i;
+ my $appdir = File::Spec->catdir( split /\:\:/, $app );
+ my $test_path =
+ File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, 'C' );
+ $type = $self->{long_type} unless -d $test_path;
+ $self->{type} = $type;
+ $self->{name} = $name;
+ $self->{class} = "$app\::$type\::$name";
+
+ # Class
+ my $path =
+ File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type );
+ my $file = $name;
+ if ( $name =~ /\:/ ) {
+ my @path = split /\:\:/, $name;
+ $file = pop @path;
+ $path = File::Spec->catdir( $path, @path );
+ }
+ $self->mk_dir($path);
+ $file = File::Spec->catfile( $path, "$file.pm" );
+ $self->{file} = $file;
+
+ # Fallback
+ else {
+ return 1 unless $self->_mk_compclass;
+ $self->_mk_comptest;
+ }
+ }
+ return 1;
+}
+
+1;
Added: Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm (rev 0)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm 2009-08-05 20:08:32 UTC (rev 11036)
@@ -0,0 +1,32 @@
+package Catalyst::Helper::ComponentGen;
+use Moose;
+use namespace::autoclean;
+extends { 'Catalyst::Helper' };
+
+# Test
+$self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' );
+$self->{test} = $self->next_test;
+
+# Helper
+if ($helper) {
+ my $comp = $self->{long_type};
+ my $class = "Catalyst::Helper::$comp\::$helper";
+ eval "require $class";
+
+ if ($@) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load helper "$class", "$@"/ );
+ }
+
+ if ( $class->can('mk_compclass') ) {
+ return 1 unless $class->mk_compclass( $self, @args );
+ }
+ else { return 1 unless $self->_mk_compclass }
+
+ if ( $class->can('mk_comptest') ) {
+ $class->mk_comptest( $self, @args );
+ }
+ else { $self->_mk_comptest }
+}
+
+1;
Modified: Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm 2009-08-05 20:07:12 UTC (rev 11035)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm 2009-08-05 20:08:32 UTC (rev 11036)
@@ -1,8 +1,6 @@
package Catalyst::Helper;
-use strict;
-use warnings;
-use base 'Class::Accessor::Fast';
+use Moose;
use Config;
use File::Spec;
use File::Path;
@@ -15,10 +13,11 @@
use Catalyst::Exception;
use Path::Class qw/dir file/;
use File::ShareDir qw/dist_dir/;
-use Moose;
-use aliased 'Path::Class::Dir';
+use MooseX::Types::Moose qw/Str Bool Int/;
+with 'MooseX::Getopt';
+
my %cache;
=head1 NAME
@@ -32,11 +31,11 @@
=cut
-
+## this stays in Helper.pm #####################################################
sub get_sharedir_file {
my ($self, @filename) = @_;
my $dist_dir;
- if (-d "inc/.author") { # Can't use sharedir if we're in a checkout
+ if (-d dir("inc", ".author") { # Can't use sharedir if we're in a checkout
# this feels horrible, better ideas?
$dist_dir = 'share';
}
@@ -67,151 +66,9 @@
return 0;
}
+################################################################################
-sub mk_app {
- my ( $self, $name ) = @_;
- # Needs to be here for PAR
- require Catalyst;
-
- if ( $name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
- warn "Error: Invalid application name.\n";
- return 0;
- }
- $self->{name } = $name;
- $self->{dir } = $name;
- $self->{dir } =~ s/\:\:/-/g;
- $self->{script } = File::Spec->catdir( $self->{dir}, 'script' );
- $self->{appprefix } = Catalyst::Utils::appprefix($name);
- $self->{appenv } = Catalyst::Utils::class2env($name);
- $self->{startperl } = -r '/usr/bin/env'
- ? '#!/usr/bin/env perl'
- : "#!$Config{perlpath} -w";
- $self->{scriptgen } = $Catalyst::Devel::CATALYST_SCRIPT_GEN || 4;
- $self->{catalyst_version} = $Catalyst::VERSION;
- $self->{author } = $self->{author} = $ENV{'AUTHOR'}
- || eval { @{ [ getpwuid($<) ] }[6] }
- || 'Catalyst developer';
-
- my $gen_scripts = ( $self->{makefile} ) ? 0 : 1;
- my $gen_makefile = ( $self->{scripts} ) ? 0 : 1;
- my $gen_app = ( $self->{scripts} || $self->{makefile} ) ? 0 : 1;
-
- if ($gen_app) {
- $self->_mk_dirs;
- $self->_mk_config;
- $self->_mk_appclass;
- $self->_mk_rootclass;
- $self->_mk_readme;
- $self->_mk_changes;
- $self->_mk_apptest;
- $self->_mk_images;
- $self->_mk_favicon;
- }
- if ($gen_makefile) {
- $self->_mk_makefile;
- }
- if ($gen_scripts) {
- $self->_mk_cgi;
- $self->_mk_fastcgi;
- $self->_mk_server;
- $self->_mk_test;
- $self->_mk_create;
- $self->_mk_information;
- }
- return $self->{dir};
-}
-
-sub mk_component {
- my $self = shift;
- my $app = shift;
- $self->{app} = $app;
- $self->{author} = $self->{author} = $ENV{'AUTHOR'}
- || eval { @{ [ getpwuid($<) ] }[6] }
- || 'A clever guy';
- $self->{base} ||= File::Spec->catdir( $FindBin::Bin, '..' );
- unless ( $_[0] =~ /^(?:model|view|controller)$/i ) {
- my $helper = shift;
- my @args = @_;
- my $class = "Catalyst::Helper::$helper";
- eval "require $class";
-
- if ($@) {
- Catalyst::Exception->throw(
- message => qq/Couldn't load helper "$class", "$@"/ );
- }
-
- if ( $class->can('mk_stuff') ) {
- return 1 unless $class->mk_stuff( $self, @args );
- }
- }
- else {
- my $type = shift;
- my $name = shift || "Missing name for model/view/controller";
- my $helper = shift;
- my @args = @_;
- return 0 if $name =~ /[^\w\:]/;
- $type = lc $type;
- $self->{long_type} = ucfirst $type;
- $type = 'M' if $type =~ /model/i;
- $type = 'V' if $type =~ /view/i;
- $type = 'C' if $type =~ /controller/i;
- my $appdir = File::Spec->catdir( split /\:\:/, $app );
- my $test_path =
- File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, 'C' );
- $type = $self->{long_type} unless -d $test_path;
- $self->{type} = $type;
- $self->{name} = $name;
- $self->{class} = "$app\::$type\::$name";
-
- # Class
- my $path =
- File::Spec->catdir( $FindBin::Bin, '..', 'lib', $appdir, $type );
- my $file = $name;
- if ( $name =~ /\:/ ) {
- my @path = split /\:\:/, $name;
- $file = pop @path;
- $path = File::Spec->catdir( $path, @path );
- }
- $self->mk_dir($path);
- $file = File::Spec->catfile( $path, "$file.pm" );
- $self->{file} = $file;
-
- # Test
- $self->{test_dir} = File::Spec->catdir( $FindBin::Bin, '..', 't' );
- $self->{test} = $self->next_test;
-
- # Helper
- if ($helper) {
- my $comp = $self->{long_type};
- my $class = "Catalyst::Helper::$comp\::$helper";
- eval "require $class";
-
- if ($@) {
- Catalyst::Exception->throw(
- message => qq/Couldn't load helper "$class", "$@"/ );
- }
-
- if ( $class->can('mk_compclass') ) {
- return 1 unless $class->mk_compclass( $self, @args );
- }
- else { return 1 unless $self->_mk_compclass }
-
- if ( $class->can('mk_comptest') ) {
- $class->mk_comptest( $self, @args );
- }
- else { $self->_mk_comptest }
- }
-
- # Fallback
- else {
- return 1 unless $self->_mk_compclass;
- $self->_mk_comptest;
- }
- }
- return 1;
-}
-
sub mk_dir {
my ( $self, $dir ) = @_;
if ( -d $dir ) {
More information about the Catalyst-commits
mailing list