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

filter: Statementstmt 76.6% 36 / 47 Branchbran 14.2% 2 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 1 totaltotal 64.3% 47 / 73 CC 8 SCAR 20.0
CC
8
Cov
62%
_build_meta
20.0
__ANON__
12.0
__ANON__
3.2
CRAP 7.4
↑ Summary
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
BranchTrueFalseTotal
if ($self->has_meta) 0 0 0
24 0 ▶ return $self->_meta->{'username'} if exists $self->_meta->{'username'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_meta->{"username"} 0 0 0
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
BranchTrueFalseTotal
if ($self->has_meta) 1 0 1
35 1 ▶ return $self->_meta->{'repo'} if exists $self->_meta->{'repo'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_meta->{"repo"} 1 0 1
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
BranchTrueFalseTotal
unless path("META.json")->exists 0 0 0
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
BranchTrueFalseTotal
unless exists $data->{"resources"}{"repository"}{"web"} 0 0 0
60  
61 0 my $repository = $data->{'resources'}{'repository'}{'web'};
62 0 ▶ return {} if $repository !~ m{^https://(?:www\.)?github\.com/([^/]+)/(.*)(?:\.git)?$};
Branch: 1 branch
BranchTrueFalseTotal
unless $repository =~ m[^https://(?:www\.)?github\.com/([^/]+)/(.*)(?:\.git)?$] 0 0 0
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__
↑ Summary