733881d570306c266dd61a8cc78bdc527c0363a6
[catagits/Catalyst-Runtime.git] / lib / Catalyst / IOC / ConstructorInjection.pm
1 package Catalyst::IOC::ConstructorInjection;
2 use Moose;
3 extends 'Bread::Board::ConstructorInjection';
4
5 with 'Bread::Board::Service::WithClass',
6      'Bread::Board::Service::WithDependencies',
7      'Bread::Board::Service::WithParameters',
8      'Catalyst::IOC::Service::WithCOMPONENT',
9      'Catalyst::IOC::Service::WithAcceptContext';
10
11 # FIXME - how much of this should move to ::WithCOMPONENT?
12 sub get {
13     my $self = shift;
14
15     my $constructor = $self->constructor_name;
16     my $component   = $self->class;
17     my $params      = $self->params;
18     my $config      = $params->{config}->{ $self->param('suffix') } || {};
19     my $app_name    = $params->{application_name};
20
21     # Stash catalyst_component_name in the config here, so that custom COMPONENT
22     # methods also pass it. local to avoid pointlessly shitting in config
23     # for the debug screen, as $component is already the key name.
24     local $config->{catalyst_component_name} = $component;
25
26     return $component->$constructor( $app_name, $config );
27 }
28
29 __PACKAGE__->meta->make_immutable;
30
31 no Moose; 1;
32
33 __END__
34
35 =pod
36
37 =head1 NAME
38
39 Catalyst::IOC::BlockInjection
40
41 =head1 AUTHORS
42
43 Catalyst Contributors, see Catalyst.pm
44
45 =head1 COPYRIGHT
46
47 This library is free software. You can redistribute it and/or modify it under
48 the same terms as Perl itself.
49
50 =cut