1 package Catalyst::IOC::Service::WithCOMPONENT;
4 with 'Bread::Board::Service';
6 sub _build_constructor_name { 'COMPONENT' }
9 my ( $orig, $self ) = @_;
11 my $constructor = $self->constructor_name;
12 my $component = $self->class;
14 unless ( $component->can( $constructor ) ) {
15 # FIXME - make some deprecation warnings
19 my $instance = eval { $self->$orig() };
21 if ( my $error = $@ ) {
23 Catalyst::Exception->throw(
24 message => qq/Couldn't instantiate component "$component", "$error"/
27 elsif (!blessed $instance) {
28 my $metaclass = Moose::Util::find_meta($component);
29 my $method_meta = $metaclass->find_method_by_name($constructor);
30 my $component_method_from = $method_meta->associated_metaclass->name;
31 my $value = defined($instance) ? $instance : 'undef';
32 Catalyst::Exception->throw(
34 qq/Couldn't instantiate component "$component", $constructor() method (from $component_method_from) didn't return an object-like value (value was $value)./
50 Catalyst::IOC::Service::WithCOMPONENT
58 Catalyst Contributors, see Catalyst.pm
62 This library is free software. You can redistribute it and/or modify it under
63 the same terms as Perl itself.