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} || {});
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?
# 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);
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(@_);
__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;
{
# 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');