File Coverage

blib/lib/Pod/Weaver/Section/Authors.pm
Criterion Covered Total %
statement 34 34 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 9 9 100.0
pod 0 1 0.0
total 46 51 90.2


line stmt bran cond sub pod time code
1             package Pod::Weaver::Section::Authors 4.018;
2             # ABSTRACT: a section listing authors
3              
4 5     5   31429 use Moose;
  5         13  
  5         44  
5             with 'Pod::Weaver::Role::Section';
6              
7             # BEGIN BOILERPLATE
8 5     5   33892 use v5.20.0;
  5         20  
9 5     5   30 use warnings;
  5         10  
  5         194  
10 5     5   30 use utf8;
  5         20  
  5         60  
11 5     5   184 no feature 'switch';
  5         13  
  5         605  
12 5     5   37 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  5         19  
  5         56  
13             # END BOILERPLATE
14              
15 5     5   627 use Pod::Elemental::Element::Nested;
  5         11  
  5         151  
16 5     5   31 use Pod::Elemental::Element::Pod5::Verbatim;
  5         19  
  5         1894  
17              
18             #pod =head1 OVERVIEW
19             #pod
20             #pod This section adds a listing of the documents authors. It expects a C<authors>
21             #pod input parameter to be an arrayref of strings. If no C<authors> parameter is
22             #pod given, it will do nothing. Otherwise, it produces a hunk like this:
23             #pod
24             #pod =head1 AUTHORS
25             #pod
26             #pod Author One <a1@example.com>
27             #pod Author Two <a2@example.com>
28             #pod
29             #pod =attr header
30             #pod
31             #pod The title of the header to be added.
32             #pod (default: "AUTHOR" or "AUTHORS")
33             #pod
34             #pod =cut
35              
36             has header => (
37             is => 'ro',
38             isa => 'Maybe[Str]',
39             );
40              
41             sub weave_section {
42 7     7 0 27 my ($self, $document, $input) = @_;
43              
44 7 50       35 return unless $input->{authors};
45              
46 7         25 my $multiple_authors = $input->{authors}->@* > 1;
47              
48             # I think I might like to have header be a callback or something, so that you
49             # can get pluralization for your own custom header. -- rjbs, 2015-03-17
50 7   33     232 my $name = $self->header || ($multiple_authors ? 'AUTHORS' : 'AUTHOR');
51              
52 7         76 $self->log_debug("adding $name section");
53 7         216 $self->log_debug("author = $_") for $input->{authors}->@*;
54              
55             my $authors = [ map {
56 14         1506 Pod::Elemental::Element::Pod5::Ordinary->new({
57             content => $_,
58             }),
59 7         154 } $input->{authors}->@* ];
60              
61             $authors = [
62             Pod::Elemental::Element::Pod5::Command->new({
63             command => 'over', content => '4',
64             }),
65             ( map {
66 7 50       1299 Pod::Elemental::Element::Pod5::Command->new({
  14         2750  
67             command => 'item', content => '*',
68             }),
69             $_,
70             } @$authors ),
71             Pod::Elemental::Element::Pod5::Command->new({
72             command => 'back', content => '',
73             }),
74             ] if $multiple_authors;
75              
76 7         2346 push $document->children->@*,
77             Pod::Elemental::Element::Nested->new({
78             type => 'command',
79             command => 'head1',
80             content => $name,
81             children => $authors,
82             });
83             }
84              
85             __PACKAGE__->meta->make_immutable;
86             1;
87              
88             __END__
89              
90             =pod
91              
92             =encoding UTF-8
93              
94             =head1 NAME
95              
96             Pod::Weaver::Section::Authors - a section listing authors
97              
98             =head1 VERSION
99              
100             version 4.018
101              
102             =head1 OVERVIEW
103              
104             This section adds a listing of the documents authors. It expects a C<authors>
105             input parameter to be an arrayref of strings. If no C<authors> parameter is
106             given, it will do nothing. Otherwise, it produces a hunk like this:
107              
108             =head1 AUTHORS
109              
110             Author One <a1@example.com>
111             Author Two <a2@example.com>
112              
113             =head1 PERL VERSION SUPPORT
114              
115             This module has the same support period as perl itself: it supports the two
116             most recent versions of perl. (That is, if the most recently released version
117             is v5.40, then this module should work on both v5.40 and v5.38.)
118              
119             Although it may work on older versions of perl, no guarantee is made that the
120             minimum required version will not be increased. The version may be increased
121             for any reason, and there is no promise that patches will be accepted to lower
122             the minimum required perl.
123              
124             =head1 ATTRIBUTES
125              
126             =head2 header
127              
128             The title of the header to be added.
129             (default: "AUTHOR" or "AUTHORS")
130              
131             =head1 AUTHOR
132              
133             Ricardo SIGNES <rjbs@semiotic.systems>
134              
135             =head1 COPYRIGHT AND LICENSE
136              
137             This software is copyright (c) 2021 by Ricardo SIGNES.
138              
139             This is free software; you can redistribute it and/or modify it under
140             the same terms as the Perl 5 programming language system itself.
141              
142             =cut