| 1 | package Dancer2::Core::Factory; | ||||||||||
| 2 | # ABSTRACT: Instantiate components by type and name | ||||||||||
| 3 | 196 | $Dancer2::Core::Factory::VERSION = '2.3.0'; | |||||||||
| 4 | 196 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 196 | ▶ | use Dancer2::Core; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 196 | ▶ | use Module::Runtime 'use_module'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 196 | ▶ | use Carp 'croak'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 977 | ▶ | sub create { | ||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 10 | 977 | my ( $class, $type, $name, %options ) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 977 | $type = Dancer2::Core::camelize($type); | |||||||||
| 13 | 977 | $name = Dancer2::Core::camelize($name); | |||||||||
| 14 | 977 | my $was_fully_qualified = ( $name =~ s/^\+// ); # strip any leading '+' | |||||||||
| 15 | 977 | ▶ | my $component_class = ( $was_fully_qualified ) ? $name : "Dancer2::${type}::${name}"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 977 | ▶ | eval { use_module($component_class); 1; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | or croak "Unable to load class for $type component $name: $@"; | ||||||||||
| 19 | |||||||||||
| 20 | 976 | return $component_class->new(%options); | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 196 | 1; | |||||||||
| 24 | |||||||||||
| 25 | __END__ | ||||||||||