[Catalyst-commits] r11067 - in
Catalyst-Devel/1.00/branches/moosify_api: lib/Catalyst
lib/Catalyst/Helper t
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Sun Aug 9 02:38:31 GMT 2009
Author: dhoss
Date: 2009-08-09 02:38:29 +0000 (Sun, 09 Aug 2009)
New Revision: 11067
Modified:
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm
Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm
Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t
Log:
committing progress
Modified: Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm 2009-08-09 02:12:18 UTC (rev 11066)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/AppGen.pm 2009-08-09 02:38:29 UTC (rev 11067)
@@ -3,24 +3,73 @@
use Moose;
use namespace::autoclean;
use Moose::Util::TypeConstraints;
+use MooseX::Types -declare [qw/ ValidAppName ValidAppComponent /];
use namespace::autoclean;
extends { 'Catalyst::Helper' };
+my $appname_re = qr/[\w:]+/;
+my $regex = qr/$appname_re::(M|V|C|Model|View|Controller)::.*/;
+
+subtype ValidAppName,
+ as Str,
+ where { /^$appname_re$/ && ! /$regex/ };
+
+subtype ValidAppComponent,
+ as Str,
+ where { /^$regex$/ };
+
+subtype Dir,
+ as Str,
+ where { s/\:\:/-/g };
+
+subtype AppEnv,
+ as Str,
+ where { /\w/ };
+
+coerce ValidAppName,
+ from ValidAppComponent,
+ via { Catalyst::Utils::class2appclass($_); },
+
+coerce AppEnv,
+ from Str,
+ via { Catalyst::Utils::class2env($_) };
+
has name => (
is => 'ro',
- isa => Str,
+ isa => 'ValidAppName',
traits => [qw(Getopt)],
cmd_aliases => 'n',
);
has dir => (
is => 'ro',
- isa => Str,
+ isa => 'Dir',
traits => [qw(Getopt)],
- cmd_aliases => 'n',
+ cmd_aliases => 'dir',
+
);
+has script => (
+ is => 'ro',
+ isa => Str,
+ traits => [qw(NoGetopt)],
+);
+
+has app_prefix => (
+ is => 'ro',
+ isa => Str,
+ traits => [qw(NoGetopt)],
+);
+
+has app_env => (
+ is => 'ro',
+ isa => 'ValidAppEnv',
+ traits => [qw(NoGetopt)],
+);
+
+
+
sub mk_app {
my ( $self, $name ) = @_;
@@ -75,68 +124,6 @@
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;
Modified: Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm 2009-08-09 02:12:18 UTC (rev 11066)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper/ComponentGen.pm 2009-08-09 02:38:29 UTC (rev 11067)
@@ -18,6 +18,7 @@
message => qq/Couldn't load helper "$class", "$@"/ );
}
+ ## NO TOUCHY
if ( $class->can('mk_compclass') ) {
return 1 unless $class->mk_compclass( $self, @args );
}
@@ -29,4 +30,68 @@
else { $self->_mk_comptest }
}
+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;
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-09 02:12:18 UTC (rev 11066)
+++ Catalyst-Devel/1.00/branches/moosify_api/lib/Catalyst/Helper.pm 2009-08-09 02:38:29 UTC (rev 11067)
@@ -354,42 +354,6 @@
}
}
-
-## 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
Modified: Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t
===================================================================
--- Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t 2009-08-09 02:12:18 UTC (rev 11066)
+++ Catalyst-Devel/1.00/branches/moosify_api/t/check_types.t 2009-08-09 02:38:29 UTC (rev 11067)
@@ -13,14 +13,26 @@
as Str,
where { /^$regex$/ };
+subtype AppEnv,
+ as Str,
+ where { /\w/ };
+
coerce ValidAppName,
from ValidAppComponent,
via { Catalyst::Utils::class2appclass($_); };
+
+coerce 'ValidAppEnv',
+ from Str,
+ via { Catalyst::Utils::class2env($_); };
+coerce AppEnv,
+ from Str,
+ via { Catalyst::Utils::class2env($_) };
+
package main;
use Test::More 'no_plan';
use Moose::Util::TypeContraints;
-use My::Types qw/ValidAppName ValidAppComponent/;
+use My::Types qw/ValidAppName ValidAppComponent AppEnv/;
my $app_tc = find_type_constraint(ValidAppName);
ok $app_tc;
@@ -33,6 +45,10 @@
ok !$comp_tc->check('MyApp');
ok $comp_tc->check('MyApp::Model::Foo');
+my $env_tc = my $comp_tc = find_type_constraint(AppEnv);
+ok $env_tc;
+#ok !$env_tc->check('');
+#ok !$env_tc->check('
is $app_tc->coerce('MyApp::Model::Foo'), 'MyApp';
done_testing;
More information about the Catalyst-commits
mailing list