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

filter: Statementstmt 76.0% 35 / 46 Branchbran 14.2% 2 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 1 totaltotal 63.8% 46 / 72 SCAR 24.5
CC
8
Cov
62%
_build_meta
20.0
__ANON__
12.0
__ANON__
3.2
CRAP 11.6
↑ Summary Build »
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::Travis;
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 Types::Standard qw/Str HashRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON::MaybeXS 'decode_json';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 with 'Badge::Depot';
12  
13 1 our $VERSION = '0.0202'; # VERSION
14 # ABSTRACT: Travis plugin for Badge::Depot
15  
16 has user => (
17 is => 'ro',
18 isa => Str,
19 lazy => 1,
20 default => sub {
21 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
22 0 ▶ if($self->has_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_meta) 0 0 0
23 0 ▶ return $self->_meta->{'username'} if exists $self->_meta->{'username'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_meta->{"username"} 0 0 0
24 }
25 },
26 1 );
27 has repo => (
28 is => 'ro',
29 isa => Str,
30 lazy => 1,
31 default => sub {
32 1 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.7
33 1 ▶ if($self->has_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_meta) 1 0 1
34 1 ▶ return $self->_meta->{'repo'} if exists $self->_meta->{'repo'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->_meta->{"repo"} 1 0 1
35 }
36 },
37 1 );
38 1 has branch => (
39 is => 'ro',
40 isa => Str,
41 default => 'master',
42 );
43 1 has _meta => (
44 is => 'ro',
45 isa => HashRef,
46 predicate => 'has_meta',
47 builder => '_build_meta',
48 );
49  
50 sub _build_meta {
51 0 ▶ my $self = shift;
Subroutine _build_meta: not called CC=4 SCAR=30.0
52  
53 0 ▶ return if !path('META.json')->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless path("META.json")->exists 0 0 0
54  
55 0 my $json = path('META.json')->slurp_utf8;
56 0 my $data = decode_json($json);
57  
58 0 ▶ return if !exists $data->{'resources'}{'repository'}{'web'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{"resources"}{"repository"}{"web"} 0 0 0
59  
60 0 my $repository = $data->{'resources'}{'repository'}{'web'};
61 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
62  
63 return {
64 0 username => $1,
65 repo => $2,
66 };
67 }
68  
69 sub BUILD {
70 1 ▶ my $self = shift;
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
71 1 $self->link_url(sprintf 'https://travis-ci.org/%s/%s', $self->user, $self->repo);
72 1 $self->image_url(sprintf 'https://api.travis-ci.org/%s/%s.svg?branch=%s', $self->user, $self->repo, $self->branch);
73 1 $self->image_alt('Travis status');
74 }
75  
76 1 1;
77  
78 __END__
79  
80 =pod
81  
82 =encoding UTF-8
83  
84 =head1 NAME
85  
86 Badge::Depot::Plugin::Travis - Travis plugin for Badge::Depot
87  
88 =head1 VERSION
89  
90 Version 0.0202, released 2015-03-22.
91  
92 =head1 SYNOPSIS
93  
94 use Badge::Depot::Plugin::Travis;
95  
96 my $badge = Badge::Depot::Plugin::Travis->new(user => 'my_name', repo => 'the_repo', branch => 'master');
97  
98 print $badge->to_html;
99 # prints '<a href="https://travis-ci.org/my_name/my_repo"><img src="https://api.travis-ci.org/my_name/my_repo.svg?branch=master" /></a>'
100  
101 =head1 DESCRIPTION
102  
103 Create a L<Travis|https://travis-ci.org> badge for a github repository.
104  
105 This class consumes the L<Badge::Depot> role.
106  
107 =head1 ATTRIBUTES
108  
109 The C<user> and C<repo> attributes are required or optional, depending on your configuration. It looks for the C<resources/repository/web> setting in C<META.json>:
110  
111 =over 4
112  
113 =item *
114  
115 If C<META.json> doesn't exist in the dist root, C<user> and C<repo> are required.
116  
117 =item *
118  
119 If C<resources/repository/web> doesn't exist (or is not a github url), C<user> and C<repo> are required.
120  
121 =back
122  
123 =head2 user
124  
125 Github username.
126  
127 =head2 repo
128  
129 Github repository.
130  
131 =head2 branch
132  
133 Github branch. Optional, C<master> by default.
134  
135 =head1 SEE ALSO
136  
137 =over 4
138  
139 =item *
140  
141 L<Badge::Depot>
142  
143 =back
144  
145 =head1 SOURCE
146  
147 L<https://github.com/Csson/p5-Badge-Depot-Plugin-Travis>
148  
149 =head1 HOMEPAGE
150  
151 L<https://metacpan.org/release/Badge-Depot-Plugin-Travis>
152  
153 =head1 AUTHOR
154  
155 Erik Carlsson <info@code301.com>
156  
157 =head1 COPYRIGHT AND LICENSE
158  
159 This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
160  
161 This is free software; you can redistribute it and/or modify it under
162 the same terms as the Perl 5 programming language system itself.
163  
164 =cut
↑ Summary Build »