File Coverage

blib/lib/Gears.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 2 2 100.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package Gears;
2             $Gears::VERSION = '0.101';
3             ###################################################
4             # ~~~~~~~~~~ We fear not our mortality ~~~~~~~~~~ #
5             # ~~~~ We'll serve to the best of our ability ~~~ #
6             # ~~~~~~ We give our lives to our masters ~~~~~~~ #
7             # ~~~~~~~~~ We vow to smite our enemies ~~~~~~~~~ #
8             ###################################################
9              
10 5     5   1782695 use v5.40;
  5         23  
11              
12             # TODO: replace with load_module when it stabilizes
13 5     5   2558 use Module::Load qw(load);
  5         7605  
  5         40  
14              
15             # TODO: replace with export_lexically when it stabilizes
16 5     5   363 use Exporter qw(import);
  5         12  
  5         1085  
17             our @EXPORT_OK = qw(
18             load_component
19             get_component_name
20             );
21              
22             sub load_component ($package)
23 152     152 1 281758 {
  152         338  
  152         172  
24 152         167 state %loaded;
25              
26             # only load package once for a given class name. Assume components have a
27             # new method (avoids Class::Inspector dependency)
28 152   66     6373 return $loaded{$package} //= do {
29 7 100       91 load $package
30             unless $package->can('new');
31 7         4017 $package;
32             };
33             }
34              
35 5         30 sub get_component_name ($package, $base)
36 5     5 1 5464 {
  5         8  
  5         6  
37 5         33 return "${base}::${package}" =~ s{^.+\^}{}r;
38             }
39              
40             __END__