File Coverage

blib/lib/App/Greple/tee/Autoload.pm
Criterion Covered Total %
statement 26 28 92.8
branch 5 8 62.5
condition 2 3 66.6
subroutine 6 7 85.7
pod 1 2 50.0
total 40 48 83.3


line stmt bran cond sub pod time code
1             package App::Greple::tee::Autoload;
2              
3 19     19   140189 use v5.24;
  19         119  
4 19     19   117 use warnings;
  19         41  
  19         1408  
5 19     19   137 use Carp;
  19         39  
  19         1781  
6              
7 19     19   152 use Exporter 'import';
  19         82  
  19         7655  
8             our @EXPORT_OK = qw(resolve);
9              
10             # Mapping of short function names to full module::function
11             my %alias = (
12             ansicolumn => 'App::ansicolumn::ansicolumn',
13             ansifold => 'App::ansifold::ansifold',
14             'cat-v' => __PACKAGE__ . '::cat_v',
15             );
16              
17             sub cat_v {
18 0     0 0 0 require App::cat::v;
19 0         0 App::cat::v->new->run(@_);
20             }
21              
22             sub resolve {
23 6     6 1 266332 my $name = shift;
24 6   66     32 my $func = $alias{$name} // $name;
25 6 50       56 if ($func =~ /^(.+)::([^:]+)$/) {
26 6         59 my($mod, $sub) = ($1, $2);
27 6 100       11 unless (defined &{$func}) {
  6         35  
28 3         282 eval "require $mod";
29 3 50       546 croak $@ if $@;
30             }
31             }
32 19     19   219 no strict 'refs';
  19         42  
  19         2503  
33 3 50       6 defined &{$func} or croak "Undefined function: $func";
  3         10  
34 3         6 \&{$func};
  3         13  
35             }
36              
37             1;
38              
39             __END__