| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::CPANModules::CheckingModuleInstalledLoadable; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
387006
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
171
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
6
|
|
|
|
|
|
|
our $DATE = '2023-08-06'; # DATE |
|
7
|
|
|
|
|
|
|
our $DIST = 'Acme-CPANModules-CheckingModuleInstalledLoadable'; # DIST |
|
8
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $LIST = { |
|
11
|
|
|
|
|
|
|
summary => 'List of modules to check if a module is installed or loadable', |
|
12
|
|
|
|
|
|
|
description => <<'_', |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
If you simply want to check that a module's `.pm` file is locatable in `@INC`, |
|
15
|
|
|
|
|
|
|
you can just do something like: |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $mod = "Foo/Bar.pm"; |
|
18
|
|
|
|
|
|
|
for my $dir (@INC) { |
|
19
|
|
|
|
|
|
|
next if ref $dir; |
|
20
|
|
|
|
|
|
|
if (-f "$dir/$mod") { |
|
21
|
|
|
|
|
|
|
print "Module $mod is installed"; |
|
22
|
|
|
|
|
|
|
last; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Or you can use something like or which |
|
27
|
|
|
|
|
|
|
does similar to the above. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
A module can also be loaded from a require hook in ~@INC~ (like in the case of |
|
30
|
|
|
|
|
|
|
fatpacked or datapacked script) and the above methods does not handle it. |
|
31
|
|
|
|
|
|
|
Instead, you'll need to use 's `check_install` or |
|
32
|
|
|
|
|
|
|
's `module_installed`: |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Module::Load::Conditional qw(check_install); |
|
35
|
|
|
|
|
|
|
if (check_install(module => "Foo::Bar")) { |
|
36
|
|
|
|
|
|
|
# Foo::Bar is installed |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
The above does not guarantee that the module will be loaded successfully. To |
|
40
|
|
|
|
|
|
|
check that, there's no other way but to actually try to load it: |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if (eval { require Foo::Bar; 1 }) { |
|
43
|
|
|
|
|
|
|
# Foo::Bar can be loaded (and was loaded!) |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
_ |
|
47
|
|
|
|
|
|
|
tags => ['task'], |
|
48
|
|
|
|
|
|
|
entries => [ |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
|
|
|
|
|
|
module=>'Module::Path', |
|
51
|
|
|
|
|
|
|
}, |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
|
|
|
|
|
|
module=>'Module::Path::More', |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
module=>'Module::Load::Conditional', |
|
57
|
|
|
|
|
|
|
}, |
|
58
|
|
|
|
|
|
|
{ |
|
59
|
|
|
|
|
|
|
module=>'Module::Installed::Tiny', |
|
60
|
|
|
|
|
|
|
}, |
|
61
|
|
|
|
|
|
|
], |
|
62
|
|
|
|
|
|
|
}; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
|
65
|
|
|
|
|
|
|
# ABSTRACT: List of modules to check if a module is installed or loadable |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |