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 5     5   2131 use Moose;
  5         2372025  
  5         36  
4             with 'MooseX::DIC::Loggable';
5              
6 5     5   39972 use aliased 'MooseX::DIC::Container::DefaultImpl';
  5         3692  
  5         29  
7 5     5   587 use aliased 'MooseX::DIC::Configuration::Code';
  5         11  
  5         28  
8 5     5   4753 use aliased 'MooseX::DIC::Configuration::YAML';
  5         15  
  5         38  
9 5     5   639 use List::Util 'reduce';
  5         16  
  5         1987  
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 8     8 0 37 my ($self) = @_;
16              
17             # Build the registry
18 8         340 $self->logger->debug("Building the registry for the container...");
19 8         167 my $registry = MooseX::DIC::ServiceRegistry->new;
20 8         5524 $self->_apply_config_to($registry);
21 8         2346 $self->logger->debug($registry->services_count." services registered");
22            
23             # Build the container
24 8         371 my $container = DefaultImpl->new( environment => $self->environment, registry => $registry );
25              
26 8         8816 $self->logger->debug("The container has been built from the registry");
27 8         113 return $container;
28             }
29              
30             sub _apply_config_to {
31 8     8   30 my ($self,$registry) = @_;
32              
33 8         101 my @config_readers = ( Code->new, YAML->new );
34              
35 8     2   6495 my $paths = reduce { $a." ".$b } @{$self->scan_path};
  2         24  
  8         395  
36 8         370 $self->logger->debug("Fetching services from scanning inside $paths...");
37 8         105 foreach my $reader (@config_readers) {
38 16         805 my @services_metadata = $reader->get_services_metadata_from_path( $self->scan_path );
39 16         119 foreach my $service_metadata (@services_metadata) {
40 19         193 $registry->add_service_definition($service_metadata);
41 19         826 $self->logger->debug("Service ".$service_metadata->class_name." was registered for interface ".$service_metadata->implements);
42             }
43             }
44             }
45              
46             1;