Badge-Depot-Plugin-Perl
view release on metacpan or search on metacpan
lib/Badge/Depot/Plugin/Perl.pm view on Meta::CPAN
use strict;
use warnings;
package Badge::Depot::Plugin::Perl;
use Moose;
use namespace::autoclean;
use MooseX::AttributeShortcuts;
use Types::Standard qw/Str Bool/;
use Types::URI qw/Uri/;
use JSON::MaybeXS 'decode_json';
use Path::Tiny;
with 'Badge::Depot';
our $VERSION = '0.0103'; # VERSION
# ABSTRACT: Perl version plugin for Badge::Depot
has version => (
is => 'ro',
isa => Str,
builder => 1,
lazy => 1,
predicate => 1,
);
has trailing => (
is => 'ro',
isa => Str,
default => '+',
);
has custom_image_url => (
is => 'ro',
isa => Uri,
coerce => 1,
default => 'https://img.shields.io/badge/perl-%s-brightgreen.svg',
);
sub BUILD {
my $self = shift;
$self->image_url(sprintf $self->custom_image_url, $self->version);
$self->image_alt(sprintf 'Requires Perl %s', $self->version);
}
sub _build_version {
my $self = shift;
return 'unknown' if !path('META.json')->exists;
my $json = path('META.json')->slurp_utf8;
my $data = decode_json($json);
return 'unknown' if !exists $data->{'prereqs'}{'runtime'}{'requires'}{'perl'};
my $version = $data->{'prereqs'}{'runtime'}{'requires'}{'perl'};
if($version =~ m{^5\.(\d{3})(\d{3})$}) {
my $major = $1;
my $minor = $2;
$major =~ s{^0+}{};
$minor =~ s{^0+}{};
$version = "5.$major" . ($minor ? ".$minor" : '');
$version .= $self->trailing;
}
elsif($version =~ m{^5\.(\d+)(?:\.(\d+))?$}) {
$version =~ s{\.0+}{.}g;
$version =~ s{\.+$}{};
$version .= $self->trailing;
( run in 0.531 second using v1.01-cache-2.11-cpan-d7f47b0818f )