1 package Catalyst::IOC::Service::WithCOMPONENT;
4 with 'Bread::Board::Service';
6 # FIXME - just till I understand how it's supposed to be done
7 # Made this so that COMPONENT is executed once,
8 # and ACCEPT_CONTEXT every call.
14 sub _build_constructor_name { 'COMPONENT' }
17 my ( $orig, $self ) = @_;
19 my $constructor = $self->constructor_name;
20 my $component = $self->class;
22 unless ( $component->can( $constructor ) ) {
23 # FIXME - make some deprecation warnings
27 if ($self->instance) {
28 return $self->instance;
31 my $instance = eval { $self->$orig() };
33 if ( my $error = $@ ) {
35 Catalyst::Exception->throw(
36 message => qq/Couldn't instantiate component "$component", "$error"/
39 elsif (!blessed $instance) {
40 my $metaclass = Moose::Util::find_meta($component);
41 my $method_meta = $metaclass->find_method_by_name($constructor);
42 my $component_method_from = $method_meta->associated_metaclass->name;
43 my $value = defined($instance) ? $instance : 'undef';
44 Catalyst::Exception->throw(
46 qq/Couldn't instantiate component "$component", $constructor() method (from $component_method_from) didn't return an object-like value (value was $value)./
50 $self->instance($instance);
64 Catalyst::Service::WithCOMPONENT
72 Catalyst Contributors, see Catalyst.pm
76 This library is free software. You can redistribute it and/or modify it under
77 the same terms as Perl itself.