From: Tomas Doran Date: Wed, 10 Aug 2011 21:48:23 +0000 (+0100) Subject: Fix the logic somewhat X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ced6f9e2e0e0b6e04249634b1ce8455bba9aa959;hp=3552850bf9f1c075b5c296cfc8d9c792956ca81e;p=catagits%2FCatalyst-Runtime.git Fix the logic somewhat --- diff --git a/t/lib/TestAppCustomContainer/Model/Bar.pm b/t/lib/TestAppCustomContainer/Model/Bar.pm index 1c92392..86dcfd2 100644 --- a/t/lib/TestAppCustomContainer/Model/Bar.pm +++ b/t/lib/TestAppCustomContainer/Model/Bar.pm @@ -4,12 +4,6 @@ extends 'Catalyst::Model'; with 'TestAppCustomContainer::Role::HoldsFoo', 'TestAppCustomContainer::Role::ACCEPT_CONTEXT'; -sub BUILD { - my ( $self ) = @_; - - $self->foo->inc_bar_got_it; -} - __PACKAGE__->meta->make_immutable; no Moose; diff --git a/t/lib/TestAppCustomContainer/Model/Baz.pm b/t/lib/TestAppCustomContainer/Model/Baz.pm index fa475e6..2efb1f5 100644 --- a/t/lib/TestAppCustomContainer/Model/Baz.pm +++ b/t/lib/TestAppCustomContainer/Model/Baz.pm @@ -4,12 +4,6 @@ extends 'Catalyst::Model'; with 'TestAppCustomContainer::Role::HoldsFoo', 'TestAppCustomContainer::Role::ACCEPT_CONTEXT'; -sub BUILD { - my ( $self ) = @_; - - $self->foo->inc_baz_got_it; -} - __PACKAGE__->meta->make_immutable; no Moose; diff --git a/t/lib/TestAppCustomContainer/Model/DefaultSetup.pm b/t/lib/TestAppCustomContainer/Model/DefaultSetup.pm index 5e80f25..8f6f704 100644 --- a/t/lib/TestAppCustomContainer/Model/DefaultSetup.pm +++ b/t/lib/TestAppCustomContainer/Model/DefaultSetup.pm @@ -1,29 +1,6 @@ -package TestAppCustomContainer::Model::Foo; +package TestAppCustomContainer::Model::DefaultSetup; use Moose; extends 'Catalyst::Model'; -with 'TestAppCustomContainer::Role::ACCEPT_CONTEXT'; - -has bar_got_it => ( - traits => ['Counter'], - is => 'ro', - isa => 'Int', - default => 0, - handles => { - inc_bar_got_it => 'inc', - }, -); - -has baz_got_it => ( - traits => ['Counter'], - is => 'ro', - isa => 'Int', - default => 0, - handles => { - inc_baz_got_it => 'inc', - }, -); - -sub COMPONENT { shift->new() } __PACKAGE__->meta->make_immutable; diff --git a/t/lib/TestAppCustomContainer/NoSugarContainer.pm b/t/lib/TestAppCustomContainer/NoSugarContainer.pm index 55fdd83..cfb5e36 100644 --- a/t/lib/TestAppCustomContainer/NoSugarContainer.pm +++ b/t/lib/TestAppCustomContainer/NoSugarContainer.pm @@ -8,50 +8,19 @@ extends 'Catalyst::IOC::Container'; sub BUILD { my $self = shift; - $self->get_sub_container('component')->add_service( - # Catalyst::IOC::ConstructorInjection gives the constructor the wrong - # parameters - Bread::Board::ConstructorInjection->new( - name => 'model_Bar', + $self->get_sub_container('model')->add_service( + Catalyst::IOC::ConstructorInjection->new( + name => 'Bar', lifecycle => 'Singleton', class => 'TestAppCustomContainer::Model::Bar', - constructor_name => 'new', dependencies => { application_name => depends_on( '/application_name' ), config => depends_on( '/config' ), - foo => Bread::Board::Dependency->new( - service_name => 'foo', - service_path => '/model/Foo', - - # FIXME - obviously this is a mistake - # what to do with ctx here? - # I have no way to get $s here, do I? - service_params => { - ctx => +{}, - accept_context_args => [ +{} ], - }, - ), - }, - ) - ); - $self->get_sub_container('model')->add_service( - Catalyst::IOC::BlockInjection->new( - name => 'Bar', - lifecycle => 'Singleton', - dependencies => [ - depends_on( '/component/model_Bar' ), - ], - block => sub { - shift->param('model_Bar'); + foo => depends_on('/model/Foo'), }, ) ); - # FIXME - this is to avoid the default service to be added - # if that happened, the app would die - $self->get_sub_container('component')->add_service( - service model_Baz => 'TestAppCustomContainer::Model::Baz', - ); $self->get_sub_container('model')->add_service( # FIXME - i think it should be a ConstructorInjection # but only BlockInjection gets ctx parameter diff --git a/t/lib/TestAppCustomContainer/Role/HoldsFoo.pm b/t/lib/TestAppCustomContainer/Role/HoldsFoo.pm index 9e0aeba..fd9ad15 100644 --- a/t/lib/TestAppCustomContainer/Role/HoldsFoo.pm +++ b/t/lib/TestAppCustomContainer/Role/HoldsFoo.pm @@ -1,11 +1,20 @@ package TestAppCustomContainer::Role::HoldsFoo; use Moose::Role; +use Test::More; use namespace::autoclean; has foo => ( is => 'ro', - isa => 'TestAppCustomContainer::Model::Foo', - required => 1, +# isa => 'TestAppCustomContainer::Model::Foo', +# required => 1, ); +sub BUILD {} + +after BUILD => sub { + my $self = shift; + ok $self->foo; + isa_ok($self->foo, 'TestAppCustomContainer::Model::DefaultSetup'); +}; + 1;