File Coverage

lib/MooseX/DIC/ContainerFactory.pm
Criterion Covered Total %
statement 34 34 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package MooseX::DIC::ContainerFactory;
2              
3 4     4   1320 use Moose;
  4         1428696  
  4         24  
4             with 'MooseX::DIC::Loggable';
5              
6 4     4   25694 use aliased 'MooseX::DIC::Container::DefaultImpl';
  4         2401  
  4         23  
7 4     4   410 use aliased 'MooseX::DIC::Configuration::Code';
  4         8  
  4         21  
8 4     4   2447 use aliased 'MooseX::DIC::Configuration::YAML';
  4         9  
  4         23  
9 4     4   400 use List::Util 'reduce';
  4         8  
  4         1348  
10              
11             has environment => (is => 'ro', isa => 'Str', default => 'default' );
12             has scan_path => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1 );
13              
14             sub build_container {
15 7     7 0 24 my ($self) = @_;
16              
17             # Build the registry
18 7         203 $self->logger->debug("Building the registry for the container...");
19 7         143 my $registry = MooseX::DIC::ServiceRegistry->new;
20 7         3207 $self->_apply_config_to($registry);
21 7         1671 $self->logger->debug($registry->services_count." services registered");
22            
23             # Build the container
24 7         253 my $container = DefaultImpl->new( environment => $self->environment, registry => $registry );
25              
26 7         4688 $self->logger->debug("The container has been built from the registry");
27 7         89 return $container;
28             }
29              
30             sub _apply_config_to {
31 7     7   20 my ($self,$registry) = @_;
32              
33 7         70 my @config_readers = ( Code->new, YAML->new );
34              
35 7     2   3357 my $paths = reduce { $a." ".$b } @{$self->scan_path};
  2         7  
  7         253  
36 7         210 $self->logger->debug("Fetching services from scanning inside $paths...");
37 7         69 foreach my $reader (@config_readers) {
38 14         423 my @services_metadata = $reader->get_services_metadata_from_path( $self->scan_path );
39 14         81 foreach my $service_metadata (@services_metadata) {
40 17         137 $registry->add_service_definition($service_metadata);
41 17         575 $self->logger->debug("Service ".$service_metadata->class_name." was registered for interface ".$service_metadata->implements);
42             }
43             }
44             }
45              
46             1;