File Coverage

blib/lib/Perinci/Sub/Dep/pm.pm
Criterion Covered Total %
statement 31 32 96.8
branch 7 10 70.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 44 48 91.6


line stmt bran cond sub pod time code
1             package Perinci::Sub::Dep::pm;
2              
3 1     1   33209 use 5.010;
  1         3  
  1         51  
4 1     1   6 use strict;
  1         2  
  1         27  
5 1     1   7 use warnings;
  1         2  
  1         24  
6              
7 1     1   661 use Perinci::Sub::DepUtil qw(declare_function_dep);
  1         444  
  1         162  
8              
9             our $VERSION = '0.29'; # VERSION
10              
11             declare_function_dep(
12             name => 'pm',
13             schema => ['str*' => {}],
14             check => sub {
15 3     3   1379 my ($val) = @_;
16 3         4 my $m = $val;
17 3         3 my $wv; # wanted version
18 3 100       16 $m =~ s/\s*(?:>=)\s*([0-9]\S*)$// and $wv = $1;
19 3         6 $m =~ s!::!/!g;
20 3         4 $m .= ".pm";
21 3         3 eval { require $m };
  3         6006  
22 3         201 my $e = $@;
23 3 100       13 return "Can't load module $val" if $e;
24 1     1   6 no strict 'refs';
  1         2  
  1         178  
25 2 100       8 if (defined $wv) {
26 1         772 require Sort::Versions;
27 1         620 my $mv = ${"$m\::VERSION"};
  1         7  
28 1 50       6 defined($mv) or return "Can't get version from $m";
29 0 0       0 return "Version of $m too old ($mv, wanted $wv)"
30             if Sort::Versions::versioncmp($wv, $mv) < 0;
31             }
32 1         4 "";
33             }
34             );
35              
36             1;
37             # ABSTRACT: Depend on a Perl module
38              
39              
40             __END__
41             =pod
42              
43             =head1 NAME
44              
45             Perinci::Sub::Dep::pm - Depend on a Perl module
46              
47             =head1 VERSION
48              
49             version 0.29
50              
51             =head1 SYNOPSIS
52              
53             # in function metadata
54             deps => {
55             ...
56             pm => 'Foo::Bar',
57             }
58              
59             # specify version requirement
60             deps => {
61             ...
62             pm => 'Foo::Bar >= 0.123',
63             }
64              
65             # specify multiple modules
66             deps => {
67             all => [
68             {pm => 'Foo'},
69             {pm => 'Bar >= 1.23'},
70             {pm => 'Baz'},
71             ],
72             }
73              
74             # specify alternatives
75             deps => {
76             any => [
77             {pm => 'Qux'},
78             {pm => 'Quux'},
79             ],
80             }
81              
82             =head1 AUTHOR
83              
84             Steven Haryanto <stevenharyanto@gmail.com>
85              
86             =head1 COPYRIGHT AND LICENSE
87              
88             This software is copyright (c) 2012 by Steven Haryanto.
89              
90             This is free software; you can redistribute it and/or modify it under
91             the same terms as the Perl 5 programming language system itself.
92              
93             =cut
94