File Coverage

blib/lib/Bot/ChatBots/Utils.pm
Criterion Covered Total %
statement 23 34 67.6
branch 2 12 16.6
condition 2 15 13.3
subroutine 8 10 80.0
pod 3 3 100.0
total 38 74 51.3


line stmt bran cond sub pod time code
1             package Bot::ChatBots::Utils;
2 3     3   58006 use strict;
  3         14  
  3         77  
3 3     3   12 use warnings;
  3         17  
  3         119  
4             { our $VERSION = '0.009'; }
5              
6 3     3   74 use 5.010;
  3         9  
7 3     3   15 use Exporter 'import';
  3         3  
  3         99  
8 3     3   908 use Module::Runtime qw< use_module >;
  3         2837  
  3         26  
9 3     3   1349 use Ouch;
  3         7726  
  3         12  
10              
11             our @EXPORT_OK = qw< load_module pipeline resolve_module >;
12              
13 1     1 1 2 sub load_module { return use_module(resolve_module(@_)) }
14              
15             sub pipeline {
16 0 0 0 0 1 0 return $_[0] if (@_ == 1) && (ref($_[0]) eq 'CODE');
17              
18 0 0       0 state $loaded = eval "use Data::Tubes '0.735002'; 1"
19             or ouch 500, 'need Data::Tubes at least 0.736 for pipeline()';
20              
21 0         0 my %opts;
22 0 0 0     0 %opts = %{shift(@_)} if (@_ && ref($_[0]) eq 'HASH');
  0         0  
23 0 0 0     0 %opts = %{pop(@_)} if (@_ && ref($_[-1]) eq 'HASH');
  0         0  
24 0   0     0 $opts{prefix} //= 'Bot::ChatBots';
25 0     0   0 $opts{tap} //= sub { ($_[0]->())[0] }
26 0 0 0     0 unless exists $opts{pump};
27              
28 0         0 return Data::Tubes::pipeline(@_, \%opts);
29             } ## end sub pipeline
30              
31             sub resolve_module {
32 25     25 1 12349 my ($name, $prefix) = @_;
33 25   100     104 $prefix //= 'Bot::ChatBots';
34 25 100       99 return substr($name, 1) if $name =~ m{\A[+^]}mxs;
35 13         48 $name =~ s{^(::)?}{::}mxs; # ensure separating "::" in front of $name
36 13         37 return $prefix . $name;
37             } ## end sub resolve_module
38              
39             42;