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   507 use Moose;
  1         2  
  1         6  
4             with 'MooseX::DIC::ServiceFactory';
5 1     1   5526 use namespace::autoclean;
  1         2  
  1         10  
6              
7 1     1   69 use aliased 'MooseX::DIC::ServiceCreationException';
  1         2  
  1         6  
8 1     1   149 use Try::Tiny;
  1         3  
  1         190  
9              
10             has container =>
11             ( is => 'ro', does => 'MooseX::DIC::Container', required => 1 );
12              
13             sub build_service {
14 1     1 0 4 my ( $self, $service_meta ) = @_;
15              
16             # The factory itself must be a non-dependency object
17 1         3 my $service;
18             try {
19 1     1   71 my $factory = $service_meta->class_name->new;
20 1         49 $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         7 };
30              
31 1         840 return $service;
32             }
33              
34             __PACKAGE__->meta->make_immutable;
35              
36             1;