--- /dev/null
+package Catalyst::IOC::BlockInjection;
+use Moose;
+extends 'Bread::Board::BlockInjection';
+
+with 'Bread::Board::Service::WithDependencies',
+ 'Bread::Board::Service::WithParameters',
+ 'Catalyst::IOC::Service::WithAcceptContext';
+
+__PACKAGE__->meta->make_immutable;
+
+no Moose; 1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catalyst::IOC::BlockInjection
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
with 'Bread::Board::Service::WithClass',
'Bread::Board::Service::WithDependencies',
'Bread::Board::Service::WithParameters',
- 'Catalyst::IOC::Service::WithCOMPONENT',
- 'Catalyst::IOC::Service::WithAcceptContext';
+ 'Catalyst::IOC::Service::WithCOMPONENT';
# FIXME - how much of this should move to ::WithCOMPONENT?
sub get {
use Hash::Util qw/lock_hash/;
use MooseX::Types::LoadableClass qw/ LoadableClass /;
use Moose::Util;
+use Catalyst::IOC::BlockInjection;
use Catalyst::IOC::ConstructorInjection;
use Module::Pluggable::Object ();
use namespace::autoclean;
my $config = $self->resolve( service => 'config' );
$self->add_sub_container(
+ $self->build_component_subcontainer
+ );
+
+ $self->add_sub_container(
$self->build_controller_subcontainer
);
);
}
+sub build_component_subcontainer {
+ my $self = shift;
+
+ return Bread::Board::Container->new(
+ name => 'component',
+ );
+}
+
sub build_application_name_service {
my $self = shift;
return unless $type;
- $self->get_sub_container($type)->add_service(
+ my $component_service_name = "${type}_${name}";
+
+ $self->get_sub_container('component')->add_service(
Catalyst::IOC::ConstructorInjection->new(
- name => $name,
+ name => $component_service_name,
class => $component,
+ lifecycle => 'Singleton',
dependencies => [
depends_on( '/application_name' ),
depends_on( '/config' ),
isa => 'Str',
default => Catalyst::Utils::class2classsuffix( $component ),
},
+ },
+ )
+ );
+
+ $self->get_sub_container($type)->add_service(
+ Catalyst::IOC::BlockInjection->new(
+ name => $name,
+ dependencies => [
+ depends_on( "/component/$component_service_name" ),
+ ],
+ parameters => {
accept_context_args => {
isa => 'ArrayRef|Undef',
required => 0,
default => undef,
},
},
+ block => sub { return shift->param($component_service_name) },
)
);
}
my $accept_context_args = $self->param('accept_context_args');
my $ac_sub = $self->accept_context_sub;
- if ( $accept_context_args && $instance->can($ac_sub) ) {
+ if ( $instance->can($ac_sub) ) {
return $instance->$ac_sub( @$accept_context_args );
}
=head1 NAME
-Catalyst::Service::WithAcceptContext
+Catalyst::IOC::Service::WithAcceptContext
=head1 DESCRIPTION
with 'Bread::Board::Service';
-# FIXME - just till I understand how it's supposed to be done
-# Made this so that COMPONENT is executed once,
-# and ACCEPT_CONTEXT every call.
-has instance => (
- is => 'rw',
- required => 0,
-);
-
sub _build_constructor_name { 'COMPONENT' }
around 'get' => sub {
return $component;
}
- if ($self->instance) {
- return $self->instance;
- }
-
my $instance = eval { $self->$orig() };
if ( my $error = $@ ) {
);
}
- $self->instance($instance);
-
return $instance;
};
=head1 NAME
-Catalyst::Service::WithCOMPONENT
+Catalyst::IOC::Service::WithCOMPONENT
=head1 DESCRIPTION