File Coverage

blib/lib/Dancer2/Core/Factory.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 27 28 96.4


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 = '0.400001';
4 146     146   3096 use Moo;
  146         13657  
  146         1004  
5 146     146   53017 use Dancer2::Core;
  146         443  
  146         4158  
6 146     146   1897 use Module::Runtime 'use_module';
  146         3786  
  146         1229  
7 146     146   7894 use Carp 'croak';
  146         416  
  146         25750  
8              
9             sub create {
10 839     839 0 37669 my ( $class, $type, $name, %options ) = @_;
11              
12 839         3908 $type = Dancer2::Core::camelize($type);
13 839         2458 $name = Dancer2::Core::camelize($name);
14 839         3050 my $component_class = "Dancer2::${type}::${name}";
15              
16 839 100       1797 eval { use_module($component_class); 1; }
  839         3453  
  838         40841  
17             or croak "Unable to load class for $type component $name: $@";
18              
19 838         11533 return $component_class->new(%options);
20             }
21              
22             1;
23              
24             __END__
25              
26             =pod
27              
28             =encoding UTF-8
29              
30             =head1 NAME
31              
32             Dancer2::Core::Factory - Instantiate components by type and name
33              
34             =head1 VERSION
35              
36             version 0.400001
37              
38             =head1 AUTHOR
39              
40             Dancer Core Developers
41              
42             =head1 COPYRIGHT AND LICENSE
43              
44             This software is copyright (c) 2023 by Alexis Sukrieh.
45              
46             This is free software; you can redistribute it and/or modify it under
47             the same terms as the Perl 5 programming language system itself.
48              
49             =cut