[Catalyst-commits] r12055 - in
Catalyst-Devel/1.00/branches/helper_refactor: lib/Catalyst t
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Fri Nov 27 03:21:18 GMT 2009
Author: t0m
Date: 2009-11-27 03:21:18 +0000 (Fri, 27 Nov 2009)
New Revision: 12055
Modified:
Catalyst-Devel/1.00/branches/helper_refactor/lib/Catalyst/Helper.pm
Catalyst-Devel/1.00/branches/helper_refactor/t/generated_app.t
Log:
Add more tests, kill off the required attributes and start instead building a data structure which is waaay more sane. Component generation now works again and has tests, except it fails for controllers - guess I probably knackered the template
Modified: Catalyst-Devel/1.00/branches/helper_refactor/lib/Catalyst/Helper.pm
===================================================================
--- Catalyst-Devel/1.00/branches/helper_refactor/lib/Catalyst/Helper.pm 2009-11-27 02:08:33 UTC (rev 12054)
+++ Catalyst-Devel/1.00/branches/helper_refactor/lib/Catalyst/Helper.pm 2009-11-27 03:21:18 UTC (rev 12055)
@@ -67,7 +67,7 @@
where { not (/[^\w:]/ or /^\d/ or /\b:\b|:{3,}/) },
message { "Error: Invalid application name '$_'." };
-has name => ( is => 'ro', isa => $appname, required => 1 );
+has name => ( is => 'ro', isa => $appname, writer => '_set_name', lazy => 1, isa => 'Str', default => sub { confess("no name") } );
my @lazy_strs = qw/ dir appprefix author rootname /;
foreach my $name (@lazy_strs) {
@@ -78,29 +78,40 @@
my $coerced_dir = subtype 'Str', where { 1 };
coerce $coerced_dir, from 'Path::Class::Dir', via { '' . $_ };
-my @lazy_dirs = qw/ lib root static images t class mod m v c base script /;
+my @lazy_dirs = qw/ class base script /;
foreach my $name (@lazy_dirs) {
has $name => ( is => 'ro', isa => $coerced_dir, coerce => 1, init_arg => undef, lazy => 1, builder => "_build_$name" );
}
-sub BUILD {
+foreach my $wrap (qw/mk_app/) {
+ before $wrap => sub {
+ my $self = shift;
+ $self->$_ for @lazy_strs, @lazy_dirs;
+ };
+}
+
+sub _build_dir_locations {
my $self = shift;
- $self->$_ for @lazy_strs, @lazy_dirs;
+ my ($script, $lib, $root, $static, $mod);
+ return (
+ script => do { $script = dir( $self->dir, 'script' ) },
+ lib => do { $lib = dir( $self->dir, 'lib' ) },
+ root => do { $root = dir( $self->dir, 'root' ) },
+ static => do {$static = dir( $root, 'static' ) },
+ images => dir( $static, 'images' ),
+ t => dir( $self->dir, 't' ),
+ mod => do { $mod = dir( $self->lib, $self->class ) },
+ m => dir( $mod, 'Model' ),
+ v => dir( $mod, 'View' ),
+ c => dir( $mod, 'Controller' ),
+ );
}
-sub _build_lib { dir( shift->dir, 'lib' ) }
-sub _build_root { dir( shift->dir, 'root' ) }
-sub _build_static { dir( shift->root, 'static' ) }
-sub _build_images { dir( shift->static, 'images' ) }
-sub _build_t { dir( shift->dir, 't' ) }
sub _build_class { dir( split( /\:\:/, shift->name ) ) }
-sub _build_mod { my $self = shift; dir( $self->lib, $self->class ) }
-sub _build_m { dir( shift->mod, 'Model' ) }
-sub _build_v { dir( shift->mod, 'View' ) }
-sub _build_c { dir( shift->mod, 'Controller' ) }
+
+
+
sub _build_base { dir( shift->dir )->absolute }
-sub _build_script { dir( shift->dir, 'script' ) }
-
sub _build_dir { my $dir = shift->name; $dir =~ s/\:\:/-/g; return $dir; }
sub _build_appprefix { Catalyst::Utils::appprefix(shift->name) }
sub _build_author {
@@ -110,6 +121,15 @@
}
sub _build_rootname { shift->name . '::Controller::Root' }
+has _app_template_data => ( isa => 'HashRef', is => 'ro', lazy => 1, builder => '_build_app_template_data' );
+sub _build_app_template_data {
+ my $self = shift;
+ my %data = (
+ $self->_build_dir_locations,
+ );
+ return \%data;
+}
+
sub mk_app {
my ( $self ) = @_;
@@ -130,7 +150,7 @@
for ( qw/ _mk_dirs _mk_config _mk_appclass _mk_rootclass _mk_readme
_mk_changes _mk_apptest _mk_images _mk_favicon/ ) {
- $self->$_;
+ $self->$_($self->_app_template_data);
}
}
if ($gen_makefile) {
@@ -140,7 +160,7 @@
for ( qw/ _mk_cgi _mk_fastcgi _mk_server
_mk_test _mk_create _mk_information
/ ) {
- $self->$_;
+ $self->$_($self->_app_template_data);
}
}
return $self->dir;
@@ -337,14 +357,15 @@
sub _mk_dirs {
my $self = shift;
- foreach my $name ( qw/ dir script lib root static images t mod m v c /) {
- $self->mk_dir( $self->$name() );
+ my @dirs = $self->_build_dir_locations;
+ while (my ($name, $location) = (shift(@dirs), shift(@dirs))) {
+ $self->mk_dir( $location );
}
}
sub _mk_appclass {
my $self = shift;
- my $mod = $self->{mod};
+ my $mod = $self->mod;
$self->render_sharedir_file( file('lib', 'MyApp.pm.tt'), "$mod.pm" );
}
Modified: Catalyst-Devel/1.00/branches/helper_refactor/t/generated_app.t
===================================================================
--- Catalyst-Devel/1.00/branches/helper_refactor/t/generated_app.t 2009-11-27 02:08:33 UTC (rev 12054)
+++ Catalyst-Devel/1.00/branches/helper_refactor/t/generated_app.t 2009-11-27 03:21:18 UTC (rev 12055)
@@ -3,6 +3,7 @@
use lib ();
use File::Temp qw/ tempdir tmpnam /;
use File::Spec;
+use FindBin qw/$Bin/;
use Catalyst::Devel;
my $dir = tempdir(CLEANUP => 1);
@@ -54,30 +55,15 @@
script/testapp_create.pl
|;
-foreach my $fn (@files) {
- ok -r $fn, "Have $fn in generated app";
- if ($fn =~ /script/) {
- ok -x $fn, "$fn is executable";
- }
- if ($fn =~ /\.p[ml]/) {
- is system($^X, '-c', $fn), 0, "$fn compiles";
- }
+foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) {
+ test_fn($fn);
}
+create_ok($_, 'My' . $_) for qw/Model View Controller/;
is system($^X, 'Makefile.PL'), 0, 'Ran Makefile.PL';
ok -e "Makefile", "Makefile generated";
is system("make"), 0, 'Run make';
-{
- local $ENV{TEST_POD} = 1;
- local $ENV{CATALYST_DEBUG} = 0;
- foreach my $test (grep { m|^t/| } @files) {
- subtest "Generated app test: $test", sub {
- require $test;
- }
- }
-}
-
my $server_script = do {
open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
local $/;
@@ -91,3 +77,34 @@
chdir('/');
done_testing;
+
+sub runperl {
+ my $comment = pop @_;
+ is system($^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_), 0, $comment;
+}
+
+sub test_fn {
+ local $ENV{TEST_POD} = 1;
+ local $ENV{CATALYST_DEBUG} = 0;
+
+ my $fn = shift;
+ ok -r $fn, "Have $fn in generated app";
+ if ($fn =~ /script/) {
+ ok -x $fn, "$fn is executable";
+ }
+ if ($fn =~ /\.p[ml]$/) {
+ runperl( '-c', $fn, "$fn compiles" );
+ }
+ if ($fn =~ /\.t$/) {
+ subtest "Generated app test: $fn", sub {
+ require $fn;
+ };
+ }
+}
+
+sub create_ok {
+ my ($type, $name) = @_;
+ runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name,
+ "'script/testapp_create.pl $type $name' ok");
+ test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", $type, $name)));
+}
More information about the Catalyst-commits
mailing list