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.020;
2             # ABSTRACT: a section listing authors
3              
4 5     5   48695 use Moose;
  5         35  
  5         58  
5             with 'Pod::Weaver::Role::Section';
6              
7             # BEGIN BOILERPLATE
8 5     5   47086 use v5.20.0;
  5         23  
9 5     5   36 use warnings;
  5         12  
  5         365  
10 5     5   36 use utf8;
  5         14  
  5         49  
11 5     5   361 no feature 'switch';
  5         13  
  5         1114  
12 5     5   41 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  5         14  
  5         52  
13             # END BOILERPLATE
14              
15 5     5   675 use Pod::Elemental::Element::Nested;
  5         15  
  5         232  
16 5     5   35 use Pod::Elemental::Element::Pod5::Verbatim;
  5         13  
  5         2828  
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 30 my ($self, $document, $input) = @_;
43              
44 7 50       36 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     301 my $name = $self->header || ($multiple_authors ? 'AUTHORS' : 'AUTHOR');
51              
52 7         59 $self->log_debug("adding $name section");
53 7         331 $self->log_debug("author = $_") for $input->{authors}->@*;
54              
55             my $authors = [ map {
56 14         2072 Pod::Elemental::Element::Pod5::Ordinary->new({
57             content => $_,
58             }),
59 7         245 } $input->{authors}->@* ];
60              
61             $authors = [
62             Pod::Elemental::Element::Pod5::Command->new({
63             command => 'over', content => '4',
64             }),
65             ( map {
66 7 50       1636 Pod::Elemental::Element::Pod5::Command->new({
  14         3596  
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         3083 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.020
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
117             released in the last two to three years. (That is, if the most recently
118             released version is v5.40, then this module should work on both v5.40 and
119             v5.38.)
120              
121             Although it may work on older versions of perl, no guarantee is made that the
122             minimum required version will not be increased. The version may be increased
123             for any reason, and there is no promise that patches will be accepted to
124             lower the minimum required perl.
125              
126             =head1 ATTRIBUTES
127              
128             =head2 header
129              
130             The title of the header to be added.
131             (default: "AUTHOR" or "AUTHORS")
132              
133             =head1 AUTHOR
134              
135             Ricardo SIGNES <cpan@semiotic.systems>
136              
137             =head1 COPYRIGHT AND LICENSE
138              
139             This software is copyright (c) 2024 by Ricardo SIGNES.
140              
141             This is free software; you can redistribute it and/or modify it under
142             the same terms as the Perl 5 programming language system itself.
143              
144             =cut