File Coverage

blib/lib/Perinci/Sub/Dep/pm.pm
Criterion Covered Total %
statement 32 32 100.0
branch 10 12 83.3
condition n/a
subroutine 7 7 100.0
pod n/a
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Perinci::Sub::Dep::pm;
2              
3 1     1   62212 use 5.010001;
  1         13  
4 1     1   5 use strict;
  1         1  
  1         17  
5 1     1   3 use warnings;
  1         2  
  1         18  
6 1     1   1456 use Log::ger;
  1         42  
  1         4  
7              
8 1     1   538 use Perinci::Sub::DepUtil qw(declare_function_dep);
  1         400  
  1         146  
9              
10             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11             our $DATE = '2022-03-20'; # DATE
12             our $DIST = 'Perinci-Sub-Dep-pm'; # DIST
13             our $VERSION = '0.301'; # VERSION
14              
15             declare_function_dep(
16             name => 'pm',
17             schema => ['str*' => {}],
18             check => sub {
19 5     5   1366 my ($val) = @_;
20              
21 5 100       14 $val = {name=>$val} unless ref $val eq 'HASH';
22              
23 5 50       12 my $mod = $val->{name} or return "BUG: Module name not specified in the 'pm' dependency";
24              
25 5         12 (my $mod_pm = "$mod.pm") =~ s!::!/!g;
26 5         7 eval { require $mod_pm };
  5         595  
27 5 100       31 return "Can't load module $mod: $@" if $@;
28 1     1   6 no strict 'refs'; ## no critic: ProhibitNoStrict
  1         2  
  1         124  
29 4 100       9 if (defined $val->{min_version}) {
30 2         415 require Version::Util;
31 2         1029 my $mod_ver = ${"$mod\::VERSION"};
  2         6  
32 2 50       5 defined($mod_ver) or return "Can't get version from module $mod";
33 2         27 log_trace "Comparing version of module $mod ($mod_ver vs minimum wanted $val->{min_version})";
34             return "Version of $mod too old ($mod_ver, minimum $val->{min_version})"
35 2 100       9 if Version::Util::version_lt($mod_ver, $val->{min_version});
36             }
37 3         52 "";
38             }
39             );
40              
41             1;
42             # ABSTRACT: Depend on a Perl module
43              
44             __END__