From: André Walker Date: Tue, 5 Jul 2011 18:02:41 +0000 (-0300) Subject: adapting unit_core_mvc.t to work (still broken) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=a9df50f8696a3856562879cfe683d18fa9557d00 adapting unit_core_mvc.t to work (still broken) --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index ccc6853..51cbb54 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1619,8 +1619,9 @@ around components => sub { for my $component ( keys %$comps ) { $components->{ $component } = $comps->{$component}; - my $type = _get_component_type($component); + my ($type, $name) = _get_component_type_name($component); +# FIXME: shouldn't the service name be $name? $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } )); } @@ -2519,7 +2520,8 @@ sub setup_components { for my $component (@comps) { my $instance = $class->components->{ $component } = $class->setup_component($component); - if ( my $type = _get_component_type($component) ) { + if ( my ($type, $name) = _get_component_type_name($component) ) { +# FIXME: shouldn't the service name be $name? $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $instance } )); } my @expanded_components = $instance->can('expand_modules') @@ -2533,7 +2535,7 @@ sub setup_components { qq{Please switch your class names to ::Model::, ::View:: and ::Controller: as appropriate.\n} ) if $deprecatedcatalyst_component_names; - if (my $type = _get_component_type($component)) { + if (my ($type, $name) = _get_component_type_name($component)) { $containers->{$type}->add_service(Bread::Board::BlockInjection->new( name => $component, block => sub { return $class->setup_component($component) } )); } @@ -2542,14 +2544,19 @@ sub setup_components { } } -sub _get_component_type { +sub _get_component_type_name { my $component = shift; my @parts = split /::/, $component; - for (@parts) { - return 'controller' if /^c|controller$/i; - return 'model' if /^m|model$/i; - return 'view' if /^v|view$/i; + while (my $type = shift @parts) { + return ('controller', join '::', @parts) + if $type =~ /^(c|controller)$/i; + + return ('model', join '::', @parts) + if $type =~ /^(m|model)$/i; + + return ('view', join '::', @parts) + if $type =~ /^(v|view)$/i; } } diff --git a/t/aggregate/unit_core_mvc.t b/t/aggregate/unit_core_mvc.t index b04c3a3..a38c0b2 100644 --- a/t/aggregate/unit_core_mvc.t +++ b/t/aggregate/unit_core_mvc.t @@ -1,29 +1,49 @@ -use Test::More tests => 51; +use Test::More; use strict; use warnings; +use Moose::Meta::Class; use_ok('Catalyst'); -my @complist = +our @complist = map { "MyMVCTestApp::$_"; } qw/C::Controller M::Model V::View Controller::C Model::M View::V Controller::Model::Dummy::Model Model::Dummy::Model/; -{ +foreach my $comp (@complist) { + Moose::Meta::Class->create( + $comp => + version => '0.1', + ); +} +our $warnings = 0; +our $loaded = 0; + +Moose::Meta::Class->create('Some::Test::Object'); +Moose::Meta::Class->create( + 'MyMVCTestApp::Model::Test::Object' => + superclasses => [ 'Catalyst::Model', 'Some::Test::Object' ], +); + +{ package MyMVCTestApp; use base qw/Catalyst/; - __PACKAGE__->components( { map { ( ref($_)||$_ , $_ ) } @complist } ); + sub locate_components { + return (@::complist, 'MyMVCTestApp::Model::Test::Object'); + } - my $thingie={}; - bless $thingie, 'Some::Test::Object'; - __PACKAGE__->components->{'MyMVCTestApp::Model::Test::Object'} = $thingie; + no warnings 'redefine'; + *Catalyst::Log::warn = sub { $::warnings++ }; + *Catalyst::Utils::ensure_class_loaded = sub { $::loaded++ if Class::MOP::is_class_loaded(shift) }; - # allow $c->log->warn to work - __PACKAGE__->setup_log; + __PACKAGE__->setup; } +ok( $warnings, 'Issues deprecated warnings' ); +is( $loaded, scalar @complist + 1, 'Loaded all components' ); + is( MyMVCTestApp->view('View'), 'MyMVCTestApp::V::View', 'V::View ok' ); is( MyMVCTestApp->controller('Controller'), @@ -61,9 +81,7 @@ is_deeply( [ sort MyMVCTestApp->models ], 'models ok'); { - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; + $warnings = 0; like (MyMVCTestApp->view , qr/^MyMVCTestApp\::(V|View)\::/ , 'view() with no defaults returns *something*'); ok( $warnings, 'view() w/o a default is random, warnings thrown' ); @@ -78,9 +96,7 @@ is ( bless ({stash=>{current_view_instance=> $view, current_view=>'MyMVCTestApp: 'current_view_instance precedes current_view ok'); { - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; + $warnings = 0; ok( my $model = MyMVCTestApp->model ); @@ -118,9 +134,7 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met is_deeply( [ MyMVCTestApp->model( qr{Test} ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); { - my $warnings = 0; - no warnings 'redefine'; - local *Catalyst::Log::warn = sub { $warnings++ }; + $warnings = 0; # object w/ regexp fallback is_deeply( [ MyMVCTestApp->model( 'Test' ) ], [ MyMVCTestApp->components->{'MyMVCTestApp::Model::Test::Object'} ], 'Object returned' ); @@ -225,3 +239,5 @@ is ( MyMVCTestApp->model , 'MyMVCTestApp::Model::M', 'default_model in class met is( MyApp::WithoutRegexFallback->controller('Foo'), undef, 'no controller Foo found'); ok( !$warnings, 'no regexp fallback warnings' ); } + +done_testing();