| 1 | 2 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Badge::Depot::Plugin::Kwalitee; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Kwalitee badge for Badge::Depot | ||||||||||||||||||||||||||||
| 8 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 9 | 2 | our $VERSION = '0.0102'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Types::Standard qw/Str HashRef/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Types::URI qw/Uri/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use JSON::MaybeXS 'decode_json'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | with 'Badge::Depot'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | 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 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | if($self->get_meta('dist')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 1 | return $self->_meta->{'dist'}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | 2 | ); | |||||||||||||||||||||||||||
| 37 | has version => ( | ||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||
| 39 | isa => Str, | ||||||||||||||||||||||||||||
| 40 | lazy => 1, | ||||||||||||||||||||||||||||
| 41 | default => sub { | ||||||||||||||||||||||||||||
| 42 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if($self->get_meta('version')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | return $self->_meta->{'version'}; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | }, | ||||||||||||||||||||||||||||
| 47 | 2 | ); | |||||||||||||||||||||||||||
| 48 | 2 | has base_url => ( | |||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||
| 50 | isa => Uri, | ||||||||||||||||||||||||||||
| 51 | coerce => 1, | ||||||||||||||||||||||||||||
| 52 | lazy => 1, | ||||||||||||||||||||||||||||
| 53 | default => 'http://badgedepot.code301.com', | ||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||
| 55 | 2 | 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_custom_image_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 1 | return sprintf '%s/badge/kwalitee/%s/%s/%s', $self->base_url, $self->author, $self->dist, $self->version; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 2 | 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_meta: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if($self->has_zilla) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | return { | ||||||||||||||||||||||||||||
| 84 | 0 | dist => $self->zilla->name, | |||||||||||||||||||||||||||
| 85 | version => $self->zilla->version, | ||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return {} if !path('META.json')->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $json = path('META.json')->slurp_utf8; | |||||||||||||||||||||||||||
| 92 | 0 | my $data = decode_json($json); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | return {} if !exists $data->{'name'} || !exists $data->{'version'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $data->{"name"} and exists $data->{"version"}
MC/DC0%0/2
exists $data->{"name"} and exists $data->{"version"}
exists $data->{"name"}
exists $data->{"version"}
Truth table0%0/3
A and B
A= exists $data->{"name"}B= exists $data->{"version"}
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | return { | ||||||||||||||||||||||||||||
| 97 | dist => $data->{'name'}, | ||||||||||||||||||||||||||||
| 98 | 0 | version => $data->{'version'}, | |||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub BUILD { | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 1 | $self->link_url(sprintf 'http://cpants.cpanauthors.org/release/%s/%s-%s', $self->author, $self->dist, $self->version); | |||||||||||||||||||||||||||
| 105 | 1 | $self->image_url($self->custom_image_url); | |||||||||||||||||||||||||||
| 106 | 1 | $self->image_alt('Distribution kwalitee'); | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | 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 | ||||||||||||||||||||||||||||