File Coverage

lib/MooseX/DIC/ServiceFactory/Factory.pm
Criterion Covered Total %
statement 18 19 94.7
branch n/a
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 24 27 88.8


line stmt bran cond sub pod time code
1             package MooseX::DIC::ServiceFactory::Factory;
2              
3 1     1   647 use Moose;
  1         4  
  1         9  
4             with 'MooseX::DIC::ServiceFactory';
5 1     1   10344 use namespace::autoclean;
  1         4  
  1         10  
6              
7 1     1   104 use aliased 'MooseX::DIC::ServiceCreationException';
  1         4  
  1         10  
8 1     1   270 use Try::Tiny;
  1         4  
  1         592  
9              
10             has container =>
11             ( is => 'ro', does => 'MooseX::DIC::Container', required => 1 );
12              
13             sub build_service {
14 1     1 0 5 my ( $self, $service_meta ) = @_;
15              
16             # The factory itself must be a non-dependency object
17 1         2 my $service;
18             try {
19 1     1   119 my $factory = $service_meta->class_name->new;
20 1         89 $service = $factory->build_service(
21             $service_meta->implements,
22             $self->container
23             );
24             }
25             catch {
26 0     0   0 ServiceCreationException->throw( message => "The factory "
27             . $service_meta->class_name
28             . " could not be created: $_" );
29 1         11 };
30              
31 1         1483 return $service;
32             }
33              
34             __PACKAGE__->meta->make_immutable;
35              
36             1;