File Coverage

blib/lib/Badge/Depot/Plugin/Kwalitee.pm
Criterion Covered Total %
statement 35 43 81.4
branch 0 6 0.0
condition 0 3 0.0
subroutine 12 13 92.3
pod 0 1 0.0
total 47 66 71.2


line stmt bran cond sub pod time code
1 1     1   13868 use 5.10.0;
  1         2  
2 1     1   3 use strict;
  1         1  
  1         18  
3 1     1   3 use warnings;
  1         0  
  1         50  
4              
5             package Badge::Depot::Plugin::Kwalitee;
6              
7             # ABSTRACT: Kwalitee badge for Badge::Depot
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '0.0102';
10              
11 1     1   466 use Moose;
  1         299462  
  1         4  
12 1     1   5196 use namespace::autoclean;
  1         5718  
  1         3  
13 1     1   532 use MooseX::AttributeShortcuts;
  1         252136  
  1         4  
14 1     1   25907 use Types::Standard qw/Str HashRef/;
  1         44501  
  1         10  
15 1     1   1006 use Types::URI qw/Uri/;
  1         89187  
  1         11  
16 1     1   716 use JSON::MaybeXS 'decode_json';
  1         2756  
  1         46  
17 1     1   12 use Path::Tiny;
  1         1  
  1         327  
18             with 'Badge::Depot';
19              
20              
21             has author => (
22             is => 'ro',
23             isa => Str,
24             required => 1,
25             );
26             has dist => (
27             is => 'ro',
28             isa => Str,
29             lazy => 1,
30             default => sub {
31             my $self = shift;
32             if($self->get_meta('dist')) {
33             return $self->_meta->{'dist'};
34             }
35             },
36             );
37             has version => (
38             is => 'ro',
39             isa => Str,
40             lazy => 1,
41             default => sub {
42             my $self = shift;
43             if($self->get_meta('version')) {
44             return $self->_meta->{'version'};
45             }
46             },
47             );
48             has base_url => (
49             is => 'ro',
50             isa => Uri,
51             coerce => 1,
52             lazy => 1,
53             default => 'http://badgedepot.code301.com',
54             );
55             has custom_image_url => (
56             is => 'ro',
57             isa => Uri,
58             coerce => 1,
59             lazy => 1,
60             builder => 1,
61             );
62              
63             sub _build_custom_image_url {
64 1     1   2 my $self = shift;
65 1         29 return sprintf '%s/badge/kwalitee/%s/%s/%s', $self->base_url, $self->author, $self->dist, $self->version;
66             }
67             has _meta => (
68             is => 'ro',
69             isa => HashRef,
70             traits => ['Hash'],
71             lazy => 1,
72             predicate => 'has_meta',
73             builder => '_build_meta',
74             handles => {
75             get_meta => 'get',
76             },
77             );
78              
79             sub _build_meta {
80 0     0   0 my $self = shift;
81              
82 0 0       0 if($self->has_zilla) {
83             return {
84 0         0 dist => $self->zilla->name,
85             version => $self->zilla->version,
86             };
87             }
88              
89 0 0       0 return {} if !path('META.json')->exists;
90              
91 0         0 my $json = path('META.json')->slurp_utf8;
92 0         0 my $data = decode_json($json);
93              
94 0 0 0     0 return {} if !exists $data->{'name'} || !exists $data->{'version'};
95              
96             return {
97             dist => $data->{'name'},
98 0         0 version => $data->{'version'},
99             };
100             }
101              
102             sub BUILD {
103 1     1 0 1 my $self = shift;
104 1         32 $self->link_url(sprintf 'http://cpants.cpanauthors.org/release/%s/%s-%s', $self->author, $self->dist, $self->version);
105 1         2523 $self->image_url($self->custom_image_url);
106 1         33 $self->image_alt('Distribution kwalitee');
107             }
108              
109             __PACKAGE__->meta->make_immutable;
110              
111             1;
112              
113             __END__
114              
115             =pod
116              
117             =encoding UTF-8
118              
119             =head1 NAME
120              
121             Badge::Depot::Plugin::Kwalitee - Kwalitee badge for Badge::Depot
122              
123              
124              
125             =begin html
126              
127             <p>
128             <img src="https://img.shields.io/badge/perl-5.10+-blue.svg" alt="Requires Perl 5.10+" />
129             <a href="https://travis-ci.org/Csson/p5-Badge-Depot-Plugin-Kwalitee"><img src="https://api.travis-ci.org/Csson/p5-Badge-Depot-Plugin-Kwalitee.svg?branch=master" alt="Travis status" /></a>
130             <a href="http://cpants.cpanauthors.org/dist/Badge-Depot-Plugin-Kwalitee-0.0102"><img src="http://badgedepot.code301.com/badge/kwalitee/CSSON/Badge-Depot-Plugin-Kwalitee/0.0102" alt="Distribution kwalitee" /></a>
131             <a href="http://matrix.cpantesters.org/?dist=Badge-Depot-Plugin-Kwalitee%200.0102"><img src="http://badgedepot.code301.com/badge/cpantesters/Badge-Depot-Plugin-Kwalitee/0.0102" alt="CPAN Testers result" /></a>
132             <img src="https://img.shields.io/badge/coverage-71.2%-red.svg" alt="coverage 71.2%" />
133             </p>
134              
135             =end html
136              
137             =head1 VERSION
138              
139             Version 0.0102, released 2016-08-11.
140              
141             =head1 SYNOPSIS
142              
143             If used standalone:
144              
145             use Badge::Depot::Plugin::Kwalitee;
146              
147             my $badge = Badge::Depot::Plugin::Kwalitee->new(dist => 'The-Dist', version => '0.1002', author => 'AUTHORID');
148              
149             print $badge->to_html;
150             # prints:
151             <a href="http://cpants.cpanauthors.org/release/AUTHORID/The-Dist-0.1002">
152             <img src="http://badgedepot.code301.com/badge/kwalitee/AUTHORID/The-Dist/0.1002" alt="Distribution kwalitee" />
153             </a>
154              
155             If used with L<Pod::Weaver::Section::Badges>, in weaver.ini:
156              
157             [Badges]
158             ; other settings
159             badge = kwalitee
160             ; set author here
161             -kwalitee_author = AUTHORID
162              
163             =head1 DESCRIPTION
164              
165             Creates a L<Kwalitee|http://cpants.cpanauthors.org> badge for a distribution.
166              
167             This class consumes the L<Badge::Depot> role.
168              
169             =head1 ATTRIBUTES
170              
171             This badge tries to use distribution meta data to set the attributes. If that is available most attributes need not be set manually. The following checks are made:
172              
173             =over 4
174              
175             =item 1
176              
177             If the badge is used via L<Pod::Weaver::Section::Badges> during a L<Dist::Zilla> build, then C<version> and C<dist> are set to the values in the Dist::Zilla object.
178              
179             =item 2
180              
181             If there is a C<META.json> in the distribution root then that is used to set C<version> and C<dist>.
182              
183             =back
184              
185             If neither of those are true, then you should also pass C<dist> and C<version> to the constructor.
186              
187             =head2 author
188              
189             The releaser's CPAN identity. Required.
190              
191             =head2 dist
192              
193             Distribution name. With dashes, not colons.
194              
195             =head2 version
196              
197             Distribution version.
198              
199             =head2 base_url
200              
201             Default: C<https://badgedepot.code301.com>
202              
203             Set this if you wish to use another instance of L<Badge::Depot::App>.
204              
205             =head1 SEE ALSO
206              
207             =over 4
208              
209             =item *
210              
211             L<Badge::Depot>
212              
213             =item *
214              
215             L<Task::Badge::Depot>
216              
217             =back
218              
219             =cut
220              
221             =head1 SOURCE
222              
223             L<https://github.com/Csson/p5-Badge-Depot-Plugin-Kwalitee>
224              
225             =head1 HOMEPAGE
226              
227             L<https://metacpan.org/release/Badge-Depot-Plugin-Kwalitee>
228              
229             =head1 AUTHOR
230              
231             Erik Carlsson <info@code301.com>
232              
233             =head1 COPYRIGHT AND LICENSE
234              
235             This software is copyright (c) 2016 by Erik Carlsson.
236              
237             This is free software; you can redistribute it and/or modify it under
238             the same terms as the Perl 5 programming language system itself.
239              
240             =cut