line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::RecordStream::OptionalRequire; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::RecordStream::OptionalRequire |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 AUTHOR |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Benjamin Bernard |
10
|
|
|
|
|
|
|
Keith Amling |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Class for optionally requiring a set of modules |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
BEGIN { |
19
|
|
|
|
|
|
|
use App::RecordStream::OptionalRequire qw(optional_require); |
20
|
|
|
|
|
|
|
optional_require(qw(Foo::Bar Biz::Zip)); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = "4.0.23"; |
26
|
|
|
|
|
|
|
|
27
|
53
|
|
|
53
|
|
23739
|
use strict; |
|
47
|
|
|
|
|
107
|
|
|
47
|
|
|
|
|
1395
|
|
28
|
48
|
|
|
48
|
|
674
|
use warnings; |
|
45
|
|
|
|
|
106
|
|
|
45
|
|
|
|
|
14178
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Set to this 0 if you don't want the warnings printed |
31
|
|
|
|
|
|
|
our $PRINT_WARNING = 1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my @missing_modules; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub import { |
36
|
31
|
|
|
31
|
|
188
|
my $class = shift; |
37
|
30
|
|
|
|
|
87
|
my $calling_package = (caller())[0]; |
38
|
30
|
|
|
|
|
89
|
return optional_use_with_caller($calling_package, @_); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# For testing and calling outside of other things... CHECK will not work in this case... |
42
|
|
|
|
|
|
|
sub optional_use { |
43
|
4
|
|
|
4
|
0
|
1320
|
my $calling_package = (caller())[0]; |
44
|
3
|
|
|
|
|
12
|
return optional_use_with_caller($calling_package, @_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub optional_use_with_caller { |
48
|
33
|
|
|
34
|
0
|
56
|
my $calling_package = shift; |
49
|
|
|
|
|
|
|
|
50
|
34
|
|
|
|
|
179
|
my $loaded; |
51
|
|
|
|
|
|
|
|
52
|
33
|
|
|
|
|
77
|
$loaded = use_module($calling_package, @_); |
53
|
33
|
|
|
|
|
72
|
my $module_name = $_[0]; |
54
|
|
|
|
|
|
|
|
55
|
34
|
100
|
|
|
|
221
|
unless ( $loaded ) { |
56
|
31
|
100
|
|
|
|
149
|
warn "$0 requires missing module $module_name\n" if ( $PRINT_WARNING ); |
57
|
31
|
|
|
|
|
73
|
push @missing_modules, $module_name; |
58
|
32
|
|
|
|
|
2026
|
return 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
8
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# CHECK runs after BEGIN blocks |
65
|
|
|
|
|
|
|
sub require_done { |
66
|
12
|
50
|
|
13
|
0
|
44
|
if ( @missing_modules ) { |
67
|
|
|
|
|
|
|
# NB: The exact phrasing of this exception is checked for in multiple |
68
|
|
|
|
|
|
|
# places. Please grep accordingly if you plan to change it below. |
69
|
13
|
|
|
|
|
384
|
die "Please install missing modules above to use this script\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub use_module { |
74
|
33
|
|
|
34
|
0
|
55
|
my $calling_package = shift; |
75
|
33
|
|
|
|
|
52
|
my $module = shift; |
76
|
34
|
|
|
|
|
202
|
my $args = join(' ', @_); |
77
|
33
|
100
|
|
|
|
97
|
if ( $args ) { |
78
|
8
|
|
|
|
|
17
|
$args = " qw($args)"; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Must use use here to invoke import |
82
|
34
|
|
|
7
|
|
1972
|
eval <
|
|
6
|
|
|
1
|
|
1200
|
|
|
1
|
|
|
1
|
|
131
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
1
|
|
127
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
1
|
|
126
|
|
|
0
|
|
|
1
|
|
0
|
|
|
0
|
|
|
1
|
|
0
|
|
|
1
|
|
|
|
|
165
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
134
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
134
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
120
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
154
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
package $calling_package; |
84
|
|
|
|
|
|
|
use $module $args; |
85
|
|
|
|
|
|
|
EVAL |
86
|
33
|
|
|
|
|
147
|
return not $@; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |