File Coverage

blib/lib/Pod/Weaver/Section/GenerateSection.pm
Criterion Covered Total %
statement 39 40 97.5
branch 5 8 62.5
condition n/a
subroutine 11 11 100.0
pod 0 2 0.0
total 55 61 90.1


line stmt bran cond sub pod time code
1             package Pod::Weaver::Section::GenerateSection;
2             $Pod::Weaver::Section::GenerateSection::VERSION = '1.06';
3 1     1   4205133 use utf8;
  1         3  
  1         8  
4              
5             ## Copyright (C) 2013-2017 Carnë Draug <carandraug+dev@gmail.com>
6             ##
7             ## This program is free software; you can redistribute it and/or modify
8             ## it under the terms of the GNU General Public License as published by
9             ## the Free Software Foundation; either version 3 of the License, or
10             ## (at your option) any later version.
11             ##
12             ## This program is distributed in the hope that it will be useful,
13             ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14             ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15             ## GNU General Public License for more details.
16             ##
17             ## You should have received a copy of the GNU General Public License
18             ## along with this program; if not, see <http://www.gnu.org/licenses/>.
19              
20 1     1   49 use strict;
  1         7  
  1         31  
21 1     1   4 use warnings;
  1         1  
  1         53  
22              
23 1     1   6 use Moose;
  1         3  
  1         9  
24 1     1   8172 use MooseX::AttributeShortcuts;
  1         187438  
  1         7  
25 1     1   43795 use MooseX::Types::Moose qw(ArrayRef Bool Int Str);
  1         2  
  1         16  
26 1     1   7077 use Pod::Elemental::Element::Nested;
  1         52470  
  1         46  
27 1     1   10 use Pod::Elemental::Element::Pod5::Ordinary;
  1         1  
  1         55  
28              
29             with (
30             'Pod::Weaver::Role::Section',
31             'Dist::Zilla::Role::TextTemplate',
32             );
33 1     1   6 use namespace::autoclean;
  1         2  
  1         7  
34              
35             # ABSTRACT: add pod section from an interpolated piece of text
36              
37              
38              
39 9     9 0 910554 sub mvp_multivalue_args { return qw(text) }
40             has text => (
41             is => 'lazy',
42             isa => ArrayRef,
43             default => sub { [] },
44             );
45              
46              
47              
48             has head => (
49             is => 'lazy',
50             isa => Int,
51             default => 1,
52             );
53              
54              
55             has title => (
56             is => 'lazy',
57             isa => Str,
58             default => sub { $_[0]->plugin_name },
59             );
60              
61              
62             has main_module_only => (
63             is => 'ro',
64             lazy => 1,
65             isa => Bool,
66             default => 0,
67             );
68              
69              
70             has is_template => (
71             is => 'lazy',
72             isa => Bool,
73             default => 1,
74             );
75              
76              
77              
78              
79             sub weave_section {
80 9     9 0 7707 my ($self, $document, $input) = @_;
81              
82 9 50       420 if ($self->main_module_only) {
83 0 0       0 return if $input->{zilla}->main_module->name ne $input->{filename};
84             }
85              
86 9         16 my $text = join ("\n", @{ $self->text });
  9         381  
87 9 100       380 if ($self->is_template) {
88             $text = $self->fill_in_string($text,
89             {
90             dist => \($input->{zilla}),
91             distmeta => \($input->{distmeta}),
92             plugin => \($self),
93              
94             name => $input->{distmeta}->{name},
95             version => $input->{distmeta}->{version},
96             homepage => $input->{distmeta}->{resources}->{homepage},
97             repository_web => $input->{distmeta}->{resources}->{repository}->{web},
98             repository_url => $input->{distmeta}->{resources}->{repository}->{url},
99             bugtracker_web => $input->{distmeta}->{resources}->{bugtracker}->{web},
100             bugtracker_email => $input->{distmeta}->{resources}->{bugtracker}->{mailto},
101 8         211 });
102             }
103 9         6358 $text = Pod::Elemental::Element::Pod5::Ordinary->new({ content => $text });
104 9 100       1898 if ($self->head) {
105 8         376 $text = Pod::Elemental::Element::Nested->new({
106             command => "head" . $self->head,
107             content => $self->title,
108             children => [$text],
109             });
110             }
111 9         3241 push @{ $document->children }, $text;
  9         363  
112             }
113              
114             __PACKAGE__->meta->make_immutable;
115             1;
116              
117             __END__
118              
119             =pod
120              
121             =encoding UTF-8
122              
123             =head1 NAME
124              
125             Pod::Weaver::Section::GenerateSection - add pod section from an interpolated piece of text
126              
127             =head1 VERSION
128              
129             version 1.06
130              
131             =head1 SYNOPSIS
132              
133             In your F<weaver.ini>
134              
135             [GenerateSection]
136             title = HOMEPAGE
137             text = This is the POD for distribution {{$name}}. Check out what we have
138             text = been up to at {{$homepage}}
139              
140             The title value can be omited if passed as the plugin name:
141              
142             [GenerateSection / HOMEPAGE]
143              
144             =head1 DESCRIPTION
145              
146             This plugin attempts to be a cross between L<Pod::Weaver::Section::Template> and
147             L<Dist::Zilla::Plugin::GenerateFile> without the generation of extra files.
148              
149             The values of text are concatenated and variable names with matching values on
150             the distribution are interpolated. Specifying the heading level allows one to
151             write down a rather long section of POD text without need for extra files. For
152             example:
153              
154             [GenerateSection / FEEDBACK]
155             head = 1
156             [GenerateSection / Reporting bugs]
157             head = 2
158             text = Please report bugs when you find them. While we do have a mailing
159             text = list, please use the bug tracker at {{$bugtracker_web}}
160             text = to report bugs
161             [GenerateSection / Homegape]
162             head = 2
163             text = Also, come check out our other projects at
164             text = {{$homepage}}
165              
166             =head1 ATTRIBUTES
167              
168             =head2 text
169              
170             The text to be added to the section. Multiple values are allowed and will be
171             concatenated. Certain sequences on the text will be replaced (see below).
172              
173             =head2 head
174              
175             The heading level of this section. If 0, there will be no heading. Defaults to 1.
176              
177             =head2 title
178              
179             The title for this section. It can optionally be omitted and passed as the
180             plugin name.
181              
182             =head2 main_module_only
183              
184             If true, it will add the text only to the main module POD. Defaults to false.
185              
186             =head2 is_template
187              
188             If false, it will not attempt to replace the {{}} entries on text. Defaults to
189             true.
190              
191             =for Pod::Coverage mvp_multivalue_args
192              
193             =head1 Text as template
194              
195             Unless the option C<is_template> is false, the text will be run through
196             L<Text::Template>. The variables C<$plugin>, C<$dist>, and C<$distmeta> will be
197             provided, set to the GenerateSection plugin, C<Dist::Zilla> object, and the
198             distribution metadata hash respectively. For convenience, the following
199             variables are also set:
200              
201             =over
202              
203             =item $name
204              
205             =item $version
206              
207             =item $homepage
208              
209             =item $repository_web
210              
211             =item $repository_url
212              
213             =item $bugtracker_web
214              
215             =item $bugtracker_email
216              
217             =back
218              
219             =for Pod::Coverage weave_section
220              
221             =head1 AUTHOR
222              
223             Carnë Draug <cdraug@cpan.org>
224              
225             =head1 COPYRIGHT AND LICENSE
226              
227             This software is Copyright (c) 2013-2017 by Carnë Draug.
228              
229             This is free software, licensed under:
230              
231             The GNU General Public License, Version 3, June 2007
232              
233             =cut