blib/lib/Badge/Depot/Plugin/Perl.pm

filter: Statementstmt 61.1% 33 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 1 totaltotal 51.8% 42 / 81 CC 7 SCAR 31.7
CC
7
Cov
49%
_build_version
56.0
BUILD
2.0
BEGIN
1.0
CRAP 23.7
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Badge::Depot::Plugin::Perl;
5  
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Types::Standard qw/Str Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Types::URI qw/Uri/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::MaybeXS 'decode_json';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 with 'Badge::Depot';
14  
15 1 our $VERSION = '0.0102'; # VERSION
16 # ABSTRACT: Perl version plugin for Badge::Depot
17  
18 1 has version => (
19 is => 'ro',
20 isa => Str,
21 builder => 1,
22 predicate => 1,
23 );
24 1 has trailing => (
25 is => 'ro',
26 isa => Str,
27 default => '+',
28 );
29 1 has custom_image_url => (
30 is => 'ro',
31 isa => Uri,
32 coerce => 1,
33 default => 'https://img.shields.io/badge/perl-%s-brightgreen.svg',
34 );
35  
36 sub BUILD {
37 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
38  
39 0 $self->image_url(sprintf $self->custom_image_url, $self->version);
40 0 $self->image_alt(sprintf 'Requires Perl %s', $self->version);
41 }
42  
43 sub _build_version {
44 0 ▶ my $self = shift;
Subroutine _build_version: not called CC=7 SCAR=40.3
45  
46 0 ▶ return 'unknown' if !path('META.json')->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless path("META.json")->exists 0 0 0
47  
48 0 my $json = path('META.json')->slurp_utf8;
49 0 my $data = decode_json($json);
50  
51 0 ▶ return 'unknown' if !exists $data->{'prereqs'}{'runtime'}{'requires'}{'perl'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{"prereqs"}{"runtime"}{"requires"}{"perl"} 0 0 0
52  
53 0 my $version = $data->{'prereqs'}{'runtime'}{'requires'}{'perl'};
54  
55 0 ▶ if($version =~ m{^5\.(\d{3})(\d{3})$}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version =~ /^5\.(\d{3})(\d{3})$/) { } 0 0 0
elsif ($version =~ /^5\.(\d+)(?:\.(\d+))?$/) { } 0 0 0
56 0 my $major = $1;
57 0 my $minor = $2;
58 0 $major =~ s{^0+}{};
59 0 $minor =~ s{^0+}{};
60 0 ▶ $version = "5.$major" . (defined $minor && length $minor ? ".$minor" : '');
Branch: 1 branch
BranchTrueFalseTotal
defined $minor && length $minor ? : 0 0 0
Condition0%0/3
defined $minor and length $minor
!ll&&!rl&&r
000
MC/DC0%0/2
defined $minor and length $minor
defined $minor length $minor
Truth table0%0/3
A and B
A= defined $minorB= length $minor
ABresult
0X0
100
111
61 0 $version .= $self->trailing;
62 }
63 elsif($version =~ m{^5\.(\d+)(?:\.(\d+))?$}) {
64 0 $version =~ s{\.0+}{.}g;
65 0 $version =~ s{\.+$}{};
66 0 $version .= $self->trailing;
67 }
68 else {
69 0 $version = 'unknown';
70 }
71 0 return $version;
72  
73 }
74  
75 1 1;
76  
77 __END__
78  
79 =pod
80  
81 =encoding UTF-8
82  
83 =head1 NAME
84  
85 Badge::Depot::Plugin::Perl - Perl version plugin for Badge::Depot
86  
87 =head1 VERSION
88  
89 Version 0.0102, released 2016-01-11.
90  
91 =head1 SYNOPSIS
92  
93 If used standalone:
94  
95 use Badge::Depot::Plugin::Perl;
96  
97 my $badge = Badge::Depot::Plugin::Perl->new(version => '5.8.5+');
98  
99 print $badge->to_html;
100 # prints '<img src="https://img.shields.io/badge/perl-5.8.5+-brightgreen.svg" />'
101  
102 If used with L<Pod::Weaver::Section::Badges>, in weaver.ini:
103  
104 [Badges]
105 ; other settings
106 badge = Perl
107 -perl_version = 5.8.5
108  
109 =head1 DESCRIPTION
110  
111 Creates a Perl version badge, like this:
112  
113 =for HTML <img src="https://img.shields.io/badge/perl-5.8.5+-brightgreen.svg" />
114  
115 =for markdown ![Requires Perl 5.8+](https://img.shields.io/badge/perl-5.8.5+-brightgreen.svg)
116  
117 This class consumes the L<Badge::Depot> role.
118  
119 =head1 ATTRIBUTES
120  
121 All attributes are optional.
122  
123 =head2 version
124  
125 The minimum supported Perl version. If it isn't given, it looks for a C<prereqs/runtime/requires/perl> entry in C<META.json> and uses that.
126  
127 If it is neither given or exists in C<META.json>, the string C<unknown> is displayed.
128  
129 =head2 trailing
130  
131 A string to add after the version, if the version is fetched from C<META.json>. Defaults to C<+>.
132  
133 Not used if C<version> is explicitly set.
134  
135 =head2 custom_image_url
136  
137 By default, this module shows an image from L<shields.io|https://shields.io>. Use this attribute to override that with a custom url. Use a C<%s> placeholder where the version should be inserted.
138  
139 =head1 SEE ALSO
140  
141 =over 4
142  
143 =item *
144  
145 L<Badge::Depot>
146  
147 =back
148  
149 =head1 SOURCE
150  
151 L<https://github.com/Csson/p5-Badge-Depot-Plugin-Perl>
152  
153 =head1 HOMEPAGE
154  
155 L<https://metacpan.org/release/Badge-Depot-Plugin-Perl>
156  
157 =head1 AUTHOR
158  
159 Erik Carlsson <info@code301.com>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 This software is copyright (c) 2016 by Erik Carlsson.
164  
165 This is free software; you can redistribute it and/or modify it under
166 the same terms as the Perl 5 programming language system itself.
167  
168 =cut
↑ Summary