6474fd5a9278a1e15d11300900e3c7d24b1395cf
[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
10 # FIXME - how much of this should move to ::WithCOMPONENT?
11 sub get {
12     my $self = shift;
13
14     my $constructor = $self->constructor_name;
15     my $component   = $self->class;
16     my $params      = $self->params;
17     my $config      = $params->{config}->{ $self->param('suffix') } || {};
18     my $app_name    = $params->{application_name};
19
20     # Stash catalyst_component_name in the config here, so that custom COMPONENT
21     # methods also pass it. local to avoid pointlessly shitting in config
22     # for the debug screen, as $component is already the key name.
23     local $config->{catalyst_component_name} = $component;
24
25     return $component->$constructor( $app_name, $config );
26 }
27
28 __PACKAGE__->meta->make_immutable;
29
30 no Moose; 1;
31
32 __END__
33
34 =pod
35
36 =head1 NAME
37
38 Catalyst::IOC::ConstructorInjection
39
40 =head1 SYNOPSIS
41
42 =head1 DESCRIPTION
43
44 =head1 AUTHORS
45
46 Catalyst Contributors, see Catalyst.pm
47
48 =head1 COPYRIGHT
49
50 This library is free software. You can redistribute it and/or modify it under
51 the same terms as Perl itself.
52
53 =cut