| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Badge::Depot::Plugin::Travis; | ||||||||||
| 5 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Types::Standard qw/Str HashRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use JSON::MaybeXS 'decode_json'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | with 'Badge::Depot'; | |||||||||
| 12 | |||||||||||
| 13 | # ABSTRACT: Travis plugin for Badge::Depot | ||||||||||
| 14 | 2 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||
| 15 | 2 | our $VERSION = '0.0203'; | |||||||||
| 16 | |||||||||||
| 17 | has user => ( | ||||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | isa => Str, | ||||||||||
| 20 | lazy => 1, | ||||||||||
| 21 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | 0 | ▶ | if($self->has_meta) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | ▶ | return $self->_meta->{'username'} if exists $self->_meta->{'username'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | } | ||||||||||
| 26 | }, | ||||||||||
| 27 | 2 | ); | |||||||||
| 28 | has repo => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | isa => Str, | ||||||||||
| 31 | lazy => 1, | ||||||||||
| 32 | 1 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||
| 33 | 1 | my $self = shift; | |||||||||
| 34 | 1 | ▶ | if($self->has_meta) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 1 | ▶ | return $self->_meta->{'repo'} if exists $self->_meta->{'repo'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | } | ||||||||||
| 37 | }, | ||||||||||
| 38 | 2 | ); | |||||||||
| 39 | 2 | has branch => ( | |||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | isa => Str, | ||||||||||
| 42 | default => 'master', | ||||||||||
| 43 | ); | ||||||||||
| 44 | 2 | has _meta => ( | |||||||||
| 45 | is => 'ro', | ||||||||||
| 46 | isa => HashRef, | ||||||||||
| 47 | predicate => 'has_meta', | ||||||||||
| 48 | builder => '_build_meta', | ||||||||||
| 49 | ); | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub _build_meta { | ||||||||
|
Subroutine
_build_meta: not called CC=4 SCAR=30.0
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | return {} if !path('META.json')->exists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 0 | my $json = path('META.json')->slurp_utf8; | |||||||||
| 57 | 0 | my $data = decode_json($json); | |||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | return {} if !exists $data->{'resources'}{'repository'}{'web'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | |||||||||||
| 61 | 0 | my $repository = $data->{'resources'}{'repository'}{'web'}; | |||||||||
| 62 | 0 | ▶ | return {} if $repository !~ m{^https://(?:www\.)?github\.com/([^/]+)/(.*)(?:\.git)?$}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | return { | ||||||||||
| 65 | 0 | username => $1, | |||||||||
| 66 | repo => $2, | ||||||||||
| 67 | }; | ||||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 1 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 71 | 1 | my $self = shift; | |||||||||
| 72 | 1 | $self->link_url(sprintf 'https://travis-ci.org/%s/%s', $self->user, $self->repo); | |||||||||
| 73 | 1 | $self->image_url(sprintf 'https://api.travis-ci.org/%s/%s.svg?branch=%s', $self->user, $self->repo, $self->branch); | |||||||||
| 74 | 1 | $self->image_alt('Travis status'); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 2 | 1; | |||||||||
| 78 | |||||||||||
| 79 | __END__ | ||||||||||