File Coverage

blib/lib/Dancer2/Core/Factory.pm
Criterion Covered Total %
statement 21 21 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Dancer2::Core::Factory;
2             # ABSTRACT: Instantiate components by type and name
3             $Dancer2::Core::Factory::VERSION = '2.1.0';
4 170     170   662660 use Moo;
  170         32376  
  170         1481  
5 170     170   85772 use Dancer2::Core;
  170         432  
  170         6292  
6 170     170   2408 use Module::Runtime 'use_module';
  170         5494  
  170         1102  
7 170     170   9238 use Carp 'croak';
  170         444  
  170         46656  
8              
9             sub create {
10 828     828 0 65608 my ( $class, $type, $name, %options ) = @_;
11              
12 828         4289 $type = Dancer2::Core::camelize($type);
13 828         3147 $name = Dancer2::Core::camelize($name);
14 828         2999 my $was_fully_qualified = ( $name =~ s/^\+// ); # strip any leading '+'
15 828 100       4198 my $component_class = ( $was_fully_qualified ) ? $name : "Dancer2::${type}::${name}";
16              
17 828 100       1989 eval { use_module($component_class); 1; }
  828         4389  
  827         41801  
18             or croak "Unable to load class for $type component $name: $@";
19              
20 827         14394 return $component_class->new(%options);
21             }
22              
23             1;
24              
25             __END__