File Coverage

lib/Pod/Weaver/Section/Badges.pm
Criterion Covered Total %
statement 133 138 96.3
branch 16 32 50.0
condition 1 3 33.3
subroutine 29 29 100.0
pod 0 1 0.0
total 179 203 88.1


line stmt bran cond sub pod time code
1 2     2   733558 use 5.14.0;
  3         1015  
  3         201  
2 2     2   459 use Moops;
  2         12249  
  2         9  
3 2     2   23876 use strict;
  2         3  
  2         53  
4 2     2   6 use warnings;
  2         2  
  2         99  
5              
6             # PODNAME: Pod::Weaver::Section::Badges
7              
8             package Pod::Weaver::Section::Name::WithBadges::PluginSearcher {
9 2     2   9 use Moose;
  2         2  
  2         13  
10 2     2   11035 use Module::Pluggable search_path => ['Badge::Depot::Plugin'], require => 1;
  2         1541  
  2         10  
11             }
12              
13 2     2   100649 class Pod::Weaver::Section::Badges
  2     2   90  
  2     2   16  
  2     2   2  
  2     2   140  
  2     2   544  
  2     2   1868  
  2     2   13  
  2     2   1936  
  2     2   2  
  2     2   13  
  2     2   103  
  2     2   3  
  2     2   122  
  2         9  
  2         3  
  2         184  
  2         72  
  2         10  
  2         2  
  2         22  
  2         6094  
  2         3  
  2         15  
  2         11036  
  2         144665  
  2         17  
  2         25979  
  2         4  
  2         19  
  2         745  
  2         6412  
  2         26  
  2         953  
  2         2361  
  2         13  
  2         1786  
  2         2  
  2         20  
  2         73846  
  2         9  
  2         81  
  2         7  
  2         3  
  2         72  
  2         10  
  2         4  
  2         91  
  2         9  
  2         6  
  2         349  
  2         6555  
  2         33  
  2         299  
  2         68783  
14             with Pod::Weaver::Role::Section
15             with Pod::Weaver::Role::AddTextToSection
16             with Pod::Weaver::Section::Badges::Utils
17             using Moose {
18              
19 2         80 our $VERSION = '0.0201'; # VERSION
20             # ABSTRACT: Add (or append) a section with badges
21 2     2   996 use MooseX::AttributeDocumented;
  2         10695  
  2         6  
22 2     2   76379 use Pod::Weaver::Section::Name::WithBadges::PluginSearcher;
  2         4  
  2         735  
23 4     4 0 16 sub mvp_multivalue_args { qw/badge/ }
24              
25 2         10 has +weaver => (
26             is => 'ro',
27             documentation_order => 0,
28             );
29 2         6303 has +logger => (
30             is => 'ro',
31             documentation_order => 0,
32             );
33 2         4914 has +plugin_name => (
34             is => 'ro',
35             documentation_order => 0,
36             );
37              
38             has badge => (
39             is => 'ro',
40             isa => ArrayRef[Str],
41             traits => ['Array'],
42 0         0 default => sub { [] },
43 2         5018 handles => {
44             all_badges => 'elements',
45             find_badge => 'first',
46             count_badges => 'count',
47             },
48             documentation => q{The name of the wanted badge, lowercased. Repeat for multiple badges. The name is everything after 'Badge::Depot::Plugin::'.},
49             documentation_default => '[]',
50             );
51 2         105329 has section => (
52             is => 'ro',
53             isa => Str,
54             default => 'NAME',
55             documentation => q{The section of pod to add the badges to, identified by its heading. The section will be created if it doesn't already exist.},
56             );
57 2         6092 has formats => (
58             is => 'ro',
59             isa => ArrayRef[Enum[qw/html markdown/]],
60             traits => ['Array'],
61             required => 1,
62             handles => {
63             all_formats => 'elements',
64             find_format => 'first',
65             has_formats => 'count',
66             },
67             documentation => q{The formats to render the badges for. Comma separated list, not multiple rows.},
68             documentation_default => '[]',
69             );
70             has badge_args => (
71             is => 'ro',
72             isa => HashRef[Str],
73 0         0 default => sub { {} },
74 2         22616 traits => ['Hash'],
75             handles => {
76             badge_args_kv => 'kv',
77             },
78             documentation_default => '{}',
79             documentation => q{badge_args is not a usable attribute in itself: All settings for badge plugins start with a dash, followed by the badge name (lowercased) and an underscore. If the badge plugin is Badge::Depot::Plugin::Travis, then all settings start with '-travis_'.},
80             );
81             has plugin_searcher => (
82             is => 'ro',
83             isa => Any,
84             init_arg => undef,
85 4         32 default => sub { Pod::Weaver::Section::Name::WithBadges::PluginSearcher->new },
86 2         62128 documentation_order => 0,
87             );
88 2         5911 has main_module_only => (
89             is => 'ro',
90             isa => Bool,
91             default => 1,
92             documentation => 'If true, the badges will only be inserted in the main module (as defined by Dist::Zilla). If false, they will be included in all modules.',
93             );
94            
95              
96 2 50   2   4292 around BUILDARGS($next: $class, $args) {
  2 50   4   4  
  2 50       504  
  2 50       5872  
  4         12  
  4         16  
  4         13  
  4         4  
  4         30  
  4         20  
97 16 50       40 $args->{'formats'} = exists $args->{'formats'} ? [ split /, ?/ => $args->{'formats'} ] : [];
98 40         44 $args->{'badge_args'} = { map { $_ => delete $args->{ $_ } } grep { /^-/ } keys %$args };
  4         16  
  4         23759  
99              
100 4         17 $class->$next($args);
101             }
102              
103 2 50   2   3688 method weave_section($document, $input) {
  2 50   4   4  
  2 50       775  
  5 50       152523  
  4         11  
  4         14  
  4         5  
  4         131  
  4         54  
104 4 50 33     15 return if $self->main_module_only && $input->{'filename'} ne $input->{'zilla'}->main_module->name;
105              
106 4         132 my $badge_objects = $self->create_badges;
107 0 50       0 return if !scalar @$badge_objects;
108              
109 4 50       59 if(!$self->has_formats) {
110 4         6 $self->log(['!!! No formats defined in weaver.ini, no badges to create.']);
111             }
112              
113 4         8 my $formats = [
114             {
115             name => 'html',
116             before => '<p>',
117             after => '</p>',
118             },
119             {
120             name => 'markdown',
121             before => undef,
122             after => undef,
123             }
124             ];
125              
126 8         7 my @output = ();
127 8         26 foreach my $format (@$formats) {
128 4         10 push @output => @{ $self->render_badges($format, $badge_objects) };
  4         12  
129             }
130              
131 4 50       97 if(scalar @output) {
132 8         9358 my $output = join "\n" => '', @output, '';
133              
134 8         19 $self->add_text_to_section($document, $output, $self->section);
135             }
136             }
137 2 50   2   2704 method log_debug($text) {
  2 50   8   4  
  2 50       227  
  5         249  
  8         14  
  8         15  
  0            
  0            
138             # silence Pod::Weaver::Role::AddTextToSection
139             }
140             }
141              
142             1;
143              
144             __END__
145              
146             =pod
147              
148             =encoding UTF-8
149              
150             =head1 NAME
151              
152             Pod::Weaver::Section::Badges - Add (or append) a section with badges
153              
154             =head1 VERSION
155              
156             Version 0.0201, released 2015-03-21.
157              
158              
159              
160             =head1 SYNOPSIS
161              
162             ; in weaver.ini
163             [Badges]
164             section = BUILD STATUS
165             formats = html
166             badge = Travis
167             badge = Gratipay
168             -travis_user = MyGithubUser
169             -travis_repo = the_repository
170             -travis_branch = master
171             -gratipay_user = ExampleName
172              
173             =head1 DESCRIPTION
174              
175             This inserts a section with status badges. The configuration in the synopsis would produce something similar to this:
176              
177             =head1 BUILD STATUS
178              
179             =begin HTML
180              
181             <p>
182             <a href="https://travis-ci.org/MyGithubUser/the_repository"><img src="https://travis-ci.org/MyGithubUser/the_repository.svg?branch=master" /></a>
183             <img src="https://img.shields.io/gratipay/ExampleName.svg" />
184             </p>
185              
186             =end HTML
187              
188             This module uses badges in the C<Badge::Depot::Plugin> namespace. See L<Task::Badge::Depot> for a list of available badges.
189             The synopsis uses the L<Badge::Depot::Plugin::Travis> and L<Badge::Depot::Plugin::Gratipay> badges.
190              
191             =head1 ATTRIBUTES
192              
193              
194             =head2 formats
195              
196             =begin HTML
197              
198             <table cellpadding="0" cellspacing="0">
199             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Enum">Enum</a> [ "<a href="https://metacpan.org/pod/Types::Standard#html">html</a>","<a href="https://metacpan.org/pod/Types::Standard#markdown">markdown</a>" ] ]</td>
200             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
201             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
202             </table>
203              
204             <p>The formats to render the badges for. Comma separated list, not multiple rows.</p>
205              
206             =end HTML
207              
208             =head2 badge
209              
210             =begin HTML
211              
212             <table cellpadding="0" cellspacing="0">
213             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
214             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>[]</code>
215              
216             </td>
217             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
218             </table>
219              
220             <p>The name of the wanted badge, lowercased. Repeat for multiple badges. The name is everything after 'Badge::Depot::Plugin::'.</p>
221              
222             =end HTML
223              
224             =head2 badge_args
225              
226             =begin HTML
227              
228             <table cellpadding="0" cellspacing="0">
229             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#HashRef">HashRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
230             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>{}</code>
231              
232             </td>
233             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
234             </table>
235              
236             <p>badge_args is not a usable attribute in itself: All settings for badge plugins start with a dash, followed by the badge name (lowercased) and an underscore. If the badge plugin is Badge::Depot::Plugin::Travis, then all settings start with '-travis_'.</p>
237              
238             =end HTML
239              
240             =head2 main_module_only
241              
242             =begin HTML
243              
244             <table cellpadding="0" cellspacing="0">
245             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a>
246              
247             </td>
248             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code>
249              
250             </td>
251             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
252             </table>
253              
254             <p>If true, the badges will only be inserted in the main module (as defined by Dist::Zilla). If false, they will be included in all modules.</p>
255              
256             =end HTML
257              
258             =head2 section
259              
260             =begin HTML
261              
262             <table cellpadding="0" cellspacing="0">
263             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Str">Str</a>
264              
265             </td>
266             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>NAME</code>
267              
268             </td>
269             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
270             </table>
271              
272             <p>The section of pod to add the badges to, identified by its heading. The section will be created if it doesn't already exist.</p>
273              
274             =end HTML
275              
276             =head1 SEE ALSO
277              
278             =over 4
279              
280             =item *
281              
282             L<Task::Badge::Depot>
283              
284             =item *
285              
286             L<Badge::Depot>
287              
288             =back
289              
290             =head1 BADGES
291              
292             =for HTML <p>
293             <img src="https://img.shields.io/badge/perl-5.14+-brightgreen.svg" />
294             <a href="https://travis-ci.org/Csson/p5-Pod-Weaver-Section-Badges"><img src="https://travis-ci.org/Csson/p5-Pod-Weaver-Section-Badges.svg?branch=master" /></a>
295             </p>
296              
297             =for markdown ![](https://img.shields.io/badge/perl-5.14+-brightgreen.svg)
298             [![](https://travis-ci.org/Csson/p5-Pod-Weaver-Section-Badges.svg?branch=master)](https://travis-ci.org/Csson/p5-Pod-Weaver-Section-Badges)
299              
300             =head1 SOURCE
301              
302             L<https://github.com/Csson/p5-Pod-Weaver-Section-Badges>
303              
304             =head1 HOMEPAGE
305              
306             L<https://metacpan.org/release/Pod-Weaver-Section-Badges>
307              
308             =head1 AUTHOR
309              
310             Erik Carlsson <info@code301.com>
311              
312             =head1 COPYRIGHT AND LICENSE
313              
314             This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
315              
316             This is free software; you can redistribute it and/or modify it under
317             the same terms as the Perl 5 programming language system itself.
318              
319             =cut