line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Package::Util::Lite; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-01-06'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
54336
|
use strict 'subs', 'vars'; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
12
|
|
|
|
|
|
|
package_exists |
13
|
|
|
|
|
|
|
list_subpackages |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub package_exists { |
17
|
1
|
|
|
1
|
|
12
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
281
|
|
18
|
|
|
|
|
|
|
|
19
|
9
|
|
|
9
|
1
|
142
|
my $pkg = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# opt |
22
|
|
|
|
|
|
|
#return unless $pkg =~ /\A\w+(::\w+)*\z/; |
23
|
|
|
|
|
|
|
|
24
|
9
|
100
|
|
|
|
33
|
if ($pkg =~ s/::(\w+)\z//) { |
25
|
3
|
|
|
|
|
5
|
return !!${$pkg . "::"}{$1 . "::"}; |
|
3
|
|
|
|
|
17
|
|
26
|
|
|
|
|
|
|
} else { |
27
|
6
|
|
|
|
|
30
|
return !!$::{$pkg . "::"}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub list_subpackages { |
32
|
5
|
|
|
5
|
1
|
11
|
my ($pkg, $recursive, $cur_res, $ref_mem) = @_; |
33
|
|
|
|
|
|
|
|
34
|
5
|
50
|
33
|
|
|
15
|
return () unless !length($pkg) || package_exists($pkg); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# this is used to avoid deep recursion. for example (the only one?) %:: and |
37
|
|
|
|
|
|
|
# %main:: point to the same thing. |
38
|
5
|
|
100
|
|
|
21
|
$ref_mem ||= {}; |
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
|
|
7
|
my $symtbl = \%{$pkg . "::"}; |
|
5
|
|
|
|
|
18
|
|
41
|
5
|
50
|
|
|
|
17
|
return () if $ref_mem->{"$symtbl"}++; |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
100
|
|
|
12
|
my $res = $cur_res || []; |
44
|
5
|
|
|
|
|
13
|
for (sort keys %$symtbl) { |
45
|
4
|
50
|
|
|
|
19
|
next unless s/::$//; |
46
|
4
|
50
|
|
|
|
11
|
my $name = (length($pkg) ? "$pkg\::" : "" ) . $_; |
47
|
4
|
|
|
|
|
7
|
push @$res, $name; |
48
|
4
|
100
|
|
|
|
14
|
list_subpackages($name, 1, $res, $ref_mem) if $recursive; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
20
|
@$res; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
# ABSTRACT: Package-related utilities |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |