| 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::Shantanutravis; | ||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.43'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | # Dependencies | ||||||||||
| 9 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Types::Standard qw/Str HashRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use JSON::MaybeXS 'decode_json'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | with 'Badge::Depot'; | |||||||||
| 15 | |||||||||||
| 16 | # ABSTRACT: Shantanu Bhadoria's Travis plugin for Badge::Depot based off Badge::Depot::Plugin::Travis | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | has user => ( | ||||||||||
| 20 | is => 'ro', | ||||||||||
| 21 | isa => Str, | ||||||||||
| 22 | lazy => 1, | ||||||||||
| 23 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 24 | 0 | my $self = shift; | |||||||||
| 25 | 0 | ▶ | if ( $self->has_meta ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | return $self->_meta->{'username'} | ||||||||||
| 27 | 0 | ▶ | if exists $self->_meta->{'username'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | }, | ||||||||||
| 30 | 1 | ); | |||||||||
| 31 | |||||||||||
| 32 | |||||||||||
| 33 | has repo => ( | ||||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | isa => Str, | ||||||||||
| 36 | lazy => 1, | ||||||||||
| 37 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 38 | 0 | my $self = shift; | |||||||||
| 39 | 0 | ▶ | if ( $self->zilla ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | return 'perl-' . $self->zilla->name; | |||||||||
| 41 | } | ||||||||||
| 42 | }, | ||||||||||
| 43 | 1 | ); | |||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | 1 | has branch => ( | |||||||||
| 47 | is => 'ro', | ||||||||||
| 48 | isa => Str, | ||||||||||
| 49 | default => 'build/master', | ||||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | 1 | has _meta => ( | |||||||||
| 53 | is => 'ro', | ||||||||||
| 54 | isa => HashRef, | ||||||||||
| 55 | predicate => 'has_meta', | ||||||||||
| 56 | builder => '_build_meta', | ||||||||||
| 57 | ); | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub _build_meta { | ||||||||
|
Subroutine
_build_meta: not called CC=5 SCAR=34.0
| |||||||||||
| 60 | 0 | my $self = shift; | |||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | if ( $self->zilla ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | return { | ||||||||||
| 64 | 0 | repo => 'perl-' . $self->zilla->name, | |||||||||
| 65 | version => $self->zilla->version, | ||||||||||
| 66 | }; | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | return {} if !path('META.json')->exists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | |||||||||||
| 71 | 0 | my $json = path('META.json')->slurp_utf8; | |||||||||
| 72 | 0 | my $data = decode_json($json); | |||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | return {} if !exists $data->{'resources'}{'repository'}{'web'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 0 | my $repository = $data->{'resources'}{'repository'}{'web'}; | |||||||||
| 77 | return {} | ||||||||||
| 78 | 0 | ▶ | if $repository !~ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | m{^https://(?:www\.)?github\.com/([^/]+)/(.*)(?:\.git)?$}; | ||||||||||
| 80 | |||||||||||
| 81 | return { | ||||||||||
| 82 | 0 | username => $1, | |||||||||
| 83 | repo => $2, | ||||||||||
| 84 | }; | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 89 | 0 | my $self = shift; | |||||||||
| 90 | 0 | $self->link_url( sprintf 'https://travis-ci.org/%s/%s', | |||||||||
| 91 | $self->user, $self->repo ); | ||||||||||
| 92 | 0 | $self->image_url( sprintf 'https://api.travis-ci.org/%s/%s.svg?branch=%s', | |||||||||
| 93 | $self->user, $self->repo, $self->branch ); | ||||||||||
| 94 | 0 | $self->image_alt('Travis status'); | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 1 | 1; | |||||||||
| 98 | |||||||||||
| 99 | __END__ | ||||||||||