File Coverage

blib/lib/Sub/Documentation/Attributes.pm
Criterion Covered Total %
statement 62 66 93.9
branch 2 2 100.0
condition 2 3 66.6
subroutine 25 29 86.2
pod 1 12 8.3
total 92 112 82.1


line stmt bran cond sub pod time code
1 1     1   585 use 5.008;
  1         2  
  1         45  
2 1     1   6 use strict;
  1         2  
  1         42  
3 1     1   5 use warnings;
  1         2  
  1         68  
4              
5             package Sub::Documentation::Attributes;
6             our $VERSION = '1.100880';
7              
8             # ABSTRACT: Use attributes to declare documentation
9 1     1   963 use Attribute::Handlers;
  1         4760  
  1         6  
10 1     1   32 use Sub::Documentation 'add_documentation';
  1         2  
  1         126  
11              
12             sub add_attr_doc {
13 13     13 1 27 my ($type, $package, $symbol, $referent, $data) = @_[0..3,5];
14              
15             # Work around an API change in Attribute::Handlers 0.79, shipped with perl
16             # 5.10, where a single scalar value is returned as an array ref when
17             # ATTR(SCALAR) is used. Not in the other ATTR cases though... We can't
18             # just require A::H 0.79 though because as of this writing it only exists
19             # as part of perl 5.10; the most recent standalone distribution on CPAN is
20             # 0.78.
21 13 100 66     45 $data = $data->[0] if ref($data) eq 'ARRAY' && @$data == 1;
22 13         43 add_documentation(
23             package => $package,
24             glob_type => ref($referent),
25 13         15 name => *{$symbol}{NAME},
26             type => $type,
27             documentation => $data,
28             );
29             }
30 1     1   21 no warnings 'redefine';
  1         2  
  1         47  
31              
32             sub UNIVERSAL::Purpose : ATTR {
33 5     5 0 3234 add_attr_doc(purpose => @_);
34 1     1   4 }
  1         1  
  1         4  
35              
36             sub UNIVERSAL::Id : ATTR {
37 0     0 0 0 add_attr_doc(id => @_);
38 1     1   240 }
  1         2  
  1         4  
39              
40             sub UNIVERSAL::Author : ATTR {
41 1     1 0 233 add_attr_doc(author => @_);
42 1     1   225 }
  1         2  
  1         4  
43              
44             sub UNIVERSAL::Param : ATTR(CODE) {
45 1     1 0 255 add_attr_doc(param => @_);
46 1     1   231 }
  1         2  
  1         3  
47              
48             sub UNIVERSAL::Returns : ATTR(CODE) {
49 1     1 0 172 add_attr_doc(returns => @_);
50 1     1   185 }
  1         1  
  1         12  
51              
52             sub UNIVERSAL::Throws : ATTR(CODE) {
53 3     3 0 444 add_attr_doc(throws => @_);
54 1     1   302 }
  1         1  
  1         5  
55              
56             sub UNIVERSAL::Example : ATTR {
57 0     0 0 0 add_attr_doc(example => @_);
58 1     1   294 }
  1         2  
  1         4  
59              
60             sub UNIVERSAL::Deprecated : ATTR {
61 1     1 0 159 add_attr_doc(deprecated => @_);
62 1     1   343 }
  1         19  
  1         4  
63              
64             sub UNIVERSAL::Default : ATTR(SCALAR) {
65 1     1 0 158 add_attr_doc(default => @_);
66 1     1   295 }
  1         2  
  1         5  
67              
68             sub UNIVERSAL::Default : ATTR(ARRAY) {
69 0     0 0 0 add_attr_doc(default => @_);
70 1     1   353 }
  1         1  
  1         4  
71              
72             sub UNIVERSAL::Default : ATTR(HASH) {
73 0     0 0 0 add_attr_doc(default => @_);
74 1     1   273 }
  1         1  
  1         9  
75             1;
76              
77              
78             __END__