Commit | Line | Data |
b7da37bd |
1 | package Catalyst::IOC::ConstructorInjection; |
2 | use Moose; |
9e6091e2 |
3 | use Catalyst::Utils (); |
b7da37bd |
4 | extends 'Bread::Board::ConstructorInjection'; |
5 | |
bf142143 |
6 | with 'Bread::Board::Service::WithClass', |
104155f6 |
7 | 'Bread::Board::Service::WithParameters', |
b489e5df |
8 | 'Bread::Board::Service::WithDependencies', |
ff0e9735 |
9 | 'Catalyst::IOC::Service::WithCOMPONENT'; |
b7da37bd |
10 | |
9e6091e2 |
11 | has config_key => ( |
12 | is => 'ro', |
13 | isa => 'Str', |
14 | lazy_build => 1, |
15 | ); |
16 | |
17 | sub _build_config_key { |
18 | Catalyst::Utils::class2classsuffix( shift->class ); |
19 | } |
20 | |
637cebbe |
21 | # FIXME - how much of this should move to ::WithCOMPONENT? |
b7da37bd |
22 | sub get { |
23 | my $self = shift; |
24 | |
25 | my $constructor = $self->constructor_name; |
b7da37bd |
26 | my $component = $self->class; |
bf142143 |
27 | my $params = $self->params; |
9e6091e2 |
28 | my $config = $params->{config}->{ $self->config_key } || {}; |
3f1b0032 |
29 | # FIXME - Is depending on the application name to pass into constructors here a good idea? |
30 | # This makes app/ctx split harder I think.. Need to think more here, but I think |
31 | # we want to pass the application in as a parameter when building the service |
32 | # rather than depending on the app name, so that later, when the app becomes an instance |
33 | # then it'll get passed in, and components can stash themselves 'per app instance' |
bf142143 |
34 | my $app_name = $params->{application_name}; |
b7da37bd |
35 | |
b7da37bd |
36 | # Stash catalyst_component_name in the config here, so that custom COMPONENT |
37 | # methods also pass it. local to avoid pointlessly shitting in config |
38 | # for the debug screen, as $component is already the key name. |
bf142143 |
39 | local $config->{catalyst_component_name} = $component; |
b7da37bd |
40 | |
637cebbe |
41 | return $component->$constructor( $app_name, $config ); |
b7da37bd |
42 | } |
43 | |
44 | __PACKAGE__->meta->make_immutable; |
45 | |
46 | no Moose; 1; |
47 | |
48 | __END__ |
49 | |
50 | =pod |
51 | |
52 | =head1 NAME |
53 | |
1ab07ed4 |
54 | Catalyst::IOC::ConstructorInjection |
55 | |
56 | =head1 SYNOPSIS |
57 | |
58 | =head1 DESCRIPTION |
b7da37bd |
59 | |
60 | =head1 AUTHORS |
61 | |
62 | Catalyst Contributors, see Catalyst.pm |
63 | |
64 | =head1 COPYRIGHT |
65 | |
66 | This library is free software. You can redistribute it and/or modify it under |
67 | the same terms as Perl itself. |
68 | |
69 | =cut |