line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
31545
|
use 5.008; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Sub::Documentation; |
6
|
|
|
|
|
|
|
our $VERSION = '1.100880'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Collect documentation for subroutines |
9
|
1
|
|
|
1
|
|
6
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
481
|
|
10
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
11
|
|
|
|
|
|
|
(util => [qw(add_documentation get_documentation search_documentation)],); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub add_documentation { |
15
|
13
|
|
|
13
|
1
|
51
|
my %args = @_; |
16
|
13
|
|
|
|
|
15
|
my $had_errors; |
17
|
13
|
|
|
|
|
19
|
for (qw(package glob_type name type documentation)) { |
18
|
65
|
50
|
|
|
|
131
|
next if defined $args{$_}; |
19
|
0
|
|
|
|
|
0
|
$had_errors++; |
20
|
0
|
|
|
|
|
0
|
warn "add_documentation() needs a '$_' key\n"; |
21
|
|
|
|
|
|
|
} |
22
|
13
|
50
|
|
|
|
25
|
die "add_documentation() had errors, aborting\n" if $had_errors; |
23
|
13
|
|
|
|
|
32
|
my %interpolate = ( |
24
|
|
|
|
|
|
|
p => $args{package}, |
25
|
|
|
|
|
|
|
'%' => '%', |
26
|
|
|
|
|
|
|
); |
27
|
13
|
50
|
|
|
|
31
|
$args{documentation} =~ s/%(.)/ $interpolate{$1} || "%$1" /ge; |
|
2
|
|
|
|
|
9
|
|
28
|
13
|
|
|
|
|
75
|
push our @doc, \%args; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_documentation { |
32
|
1
|
|
|
1
|
1
|
120
|
our @doc; |
33
|
1
|
50
|
|
|
|
11
|
wantarray ? @doc : \@doc; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub search_documentation { |
37
|
0
|
|
|
0
|
1
|
|
my %args = @_; |
38
|
0
|
|
|
|
|
|
my @found; |
39
|
0
|
|
|
|
|
|
for my $doc (our @doc) { |
40
|
0
|
|
|
|
|
|
my $match = 1; |
41
|
0
|
|
|
|
|
|
while (my ($key, $value) = each %args) { |
42
|
0
|
0
|
|
|
|
|
if (defined $doc->{$key}) { |
43
|
0
|
|
|
|
|
|
my $ref = ref $doc->{$key}; |
44
|
0
|
0
|
|
|
|
|
if ($ref eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
$match = 0 unless grep { $_ eq $value } @{ $doc->{$key} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} elsif ($ref eq '') { |
47
|
0
|
0
|
|
|
|
|
$match = 0 unless $doc->{$key} eq $value; |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
|
die "search_documentation(): key [$key] has unsupported value ref $ref\n"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
|
$match = 0; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
0
|
0
|
|
|
|
|
push @found, $doc if $match; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
0
|
|
|
|
|
wantarray ? @found : \@found; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |