some playing
André Walker [Wed, 17 Aug 2011 01:02:54 +0000 (22:02 -0300)]
lib/Catalyst/IOC/ConstructorInjection.pm
lib/Catalyst/IOC/Container.pm
lib/Catalyst/IOC/LifeCycle/Request.pm
t/lib/TestAppCustomContainer/Controller/Root.pm
t/lib/TestCustomContainer.pm

index ec83244..8062a8e 100644 (file)
@@ -27,8 +27,8 @@ has config => (
 around resolve_dependencies => sub {
     my ($orig, $self, @args) = @_;
     my %deps = $self->$orig(@args);
-    use Data::Dumper;
-        warn("$self Resolve deps" . Data::Dumper::Dumper(\%deps));
+#    use Data::Dumper;
+#        warn("$self Resolve deps" . Data::Dumper::Dumper(\%deps));
     my $app_config = delete $deps{__catalyst_config};
     my $conf_key = Catalyst::Utils::class2classsuffix($self->catalyst_component_name);
     $self->_set_config($app_config->{$conf_key} || {});
@@ -42,7 +42,7 @@ sub get {
 
     my $params = $self->params;
     my %config = (%{ $self->config }, %{ $params });
-    warn(Data::Dumper::Dumper(\%config));
+#    warn(Data::Dumper::Dumper(\%config));
     $self->_clear_config;
 
     # FIXME - Is depending on the application name to pass into constructors here a good idea?
index 89169de..7a0d65f 100644 (file)
@@ -639,6 +639,9 @@ sub get_all_components {
     # FIXME - if we're getting from these containers, we need to either:
     #   - pass 'ctx' and 'accept_context_args' OR
     #   - make these params optional
+    # big problem when setting up the dispatcher - this method is called
+    # as $container->get_all_components('MyApp'). What to do with Request
+    # life cycles?
     foreach my $type (qw/model view controller /) {
         my $container = $self->get_sub_container($type);
 
index 39468d7..bbdde3f 100644 (file)
@@ -3,16 +3,18 @@ use Moose::Role;
 use namespace::autoclean;
 use Carp;
 with 'Bread::Board::LifeCycle';
+use Data::Dumper;
 
 around get => sub {
-    my $orig = shift;
-    my $self = shift;
-
-    # FIXME - ugly, but the only way it'll work
-    # we should find out why
-    my $ctx = {@_}->{'ctx'}
-        or confess qq/This component has a Request lifecycle.\n/ .
-                   qq/The 'ctx' parameter is mandatory./;
+    my $orig   = shift;
+    my $self   = shift;
+    my $params = {@_};
+
+    my $ctx = exists $params->{ctx} && ref $params->{ctx}
+            ? $params->{ctx}
+            : undef
+            ;
+    return $self->$orig(@_) unless $ctx;
 
     my $stash_key = "__Catalyst_IOC_LifeCycle_Request_" . $self->name;
     return $ctx->stash->{$stash_key} ||= $self->$orig(@_);
index a6ddb2f..311d006 100644 (file)
@@ -4,29 +4,9 @@ BEGIN { extends 'Catalyst::Controller' }
 
 __PACKAGE__->config(namespace => '');
 
-sub container_class :Local {
+sub index : Default {
     my ($self, $c) = @_;
-    $c->res->body($c->config->{container_class});
-}
-
-sub container_isa :Local {
-    my ($self, $c) = @_;
-    $c->res->body(ref $c->container);
-}
-
-sub get_model_bar :Local {
-    my ($self, $c) = @_;
-    $c->res->body(ref $c->model('Bar'));
-}
-
-sub get_model_baz :Local {
-    my ($self, $c) = @_;
-    $c->res->body(ref $c->model('Baz'));
-}
-
-sub get_model_foo :Local {
-    my ($self, $c) = @_;
-    $c->res->body(ref $c->model('DefaultSetup'));
+    $c->res->body('foo');
 }
 
 __PACKAGE__->meta->make_immutable;
index d7b1e6a..e5996ca 100644 (file)
@@ -44,9 +44,9 @@ sub BUILD {
 
     {
         # DefaultSetup ACCEPT_CONTEXT called - total: 1
-        ok(my ($res, $c) = ctx_request('/get_model_baz'), 'request');
+        ok(my ($res, $c) = ctx_request('/'), 'request');
         ok($res->is_success, 'request 2xx');
-        is($res->content, 'TestAppCustomContainer::Model::RequestLifeCycle', 'content is expected');
+        is($res->content, 'foo', 'content is expected');
 
         ok(my $baz = $c->container->get_sub_container('model')->resolve(service => 'RequestLifeCycle', parameters => { ctx => $c, accept_context_args => [$c] } ), 'fetching RequestLifeCycle');
         isa_ok($baz, 'TestAppCustomContainer::Model::RequestLifeCycle');