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.019;
2             # ABSTRACT: a section listing authors
3              
4 5     5   34113 use Moose;
  5         12  
  5         46  
5             with 'Pod::Weaver::Role::Section';
6              
7             # BEGIN BOILERPLATE
8 5     5   36860 use v5.20.0;
  5         19  
9 5     5   33 use warnings;
  5         14  
  5         229  
10 5     5   45 use utf8;
  5         13  
  5         48  
11 5     5   215 no feature 'switch';
  5         13  
  5         651  
12 5     5   45 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  5         19  
  5         48  
13             # END BOILERPLATE
14              
15 5     5   636 use Pod::Elemental::Element::Nested;
  5         12  
  5         183  
16 5     5   53 use Pod::Elemental::Element::Pod5::Verbatim;
  5         19  
  5         2068  
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 28 my ($self, $document, $input) = @_;
43              
44 7 50       37 return unless $input->{authors};
45              
46 7         26 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     288 my $name = $self->header || ($multiple_authors ? 'AUTHORS' : 'AUTHOR');
51              
52 7         72 $self->log_debug("adding $name section");
53 7         258 $self->log_debug("author = $_") for $input->{authors}->@*;
54              
55             my $authors = [ map {
56 14         1533 Pod::Elemental::Element::Pod5::Ordinary->new({
57             content => $_,
58             }),
59 7         191 } $input->{authors}->@* ];
60              
61             $authors = [
62             Pod::Elemental::Element::Pod5::Command->new({
63             command => 'over', content => '4',
64             }),
65             ( map {
66 7 50       1330 Pod::Elemental::Element::Pod5::Command->new({
  14         3059  
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         2424 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.019
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
114              
115             This module should work on any version of perl still receiving updates from
116             the Perl 5 Porters. This means it should work on any version of perl released
117             in the last two to three years. (That is, if the most recently released
118             version is v5.40, then this module should work on both v5.40 and v5.38.)
119              
120             Although it may work on older versions of perl, no guarantee is made that the
121             minimum required version will not be increased. The version may be increased
122             for any reason, and there is no promise that patches will be accepted to lower
123             the minimum required perl.
124              
125             =head1 ATTRIBUTES
126              
127             =head2 header
128              
129             The title of the header to be added.
130             (default: "AUTHOR" or "AUTHORS")
131              
132             =head1 AUTHOR
133              
134             Ricardo SIGNES <cpan@semiotic.systems>
135              
136             =head1 COPYRIGHT AND LICENSE
137              
138             This software is copyright (c) 2023 by Ricardo SIGNES.
139              
140             This is free software; you can redistribute it and/or modify it under
141             the same terms as the Perl 5 programming language system itself.
142              
143             =cut