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 = '1.0.0';
4 147     147   3240 use Moo;
  147         14044  
  147         1017  
5 147     147   53670 use Dancer2::Core;
  147         427  
  147         4355  
6 147     147   1955 use Module::Runtime 'use_module';
  147         3994  
  147         1313  
7 147     147   8303 use Carp 'croak';
  147         489  
  147         27558  
8              
9             sub create {
10 844     844 0 36325 my ( $class, $type, $name, %options ) = @_;
11              
12 844         3996 $type = Dancer2::Core::camelize($type);
13 844         2463 $name = Dancer2::Core::camelize($name);
14 844         3277 my $component_class = "Dancer2::${type}::${name}";
15              
16 844 100       1767 eval { use_module($component_class); 1; }
  844         3414  
  843         41220  
17             or croak "Unable to load class for $type component $name: $@";
18              
19 843         11319 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 1.0.0
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