blib/lib/Dist/Zilla/Plugin/TravisCI.pm

filter: Statementstmt 84.7% 117 / 138 Branchbran 56.8% 25 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.1% 16 / 17 Podpod 20.0% 1 / 5 totaltotal 77.9% 159 / 204 CC 24 SCAR 29.6
CC
24
Cov
78%
build_travis_yml
34.1
gather_files
2.6
after_build
2.0
CRAP 19.3
↑ Summary
1 package Dist::Zilla::Plugin::TravisCI;
2 4 our $AUTHORITY = 'cpan:GETTY';
3 # ABSTRACT: Integrating the generation of .travis.yml into your dzil
4 4 $Dist::Zilla::Plugin::TravisCI::VERSION = '0.014';
5 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Dist::Zilla::File::FromCode;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 with 'Dist::Zilla::Role::FileGatherer','Dist::Zilla::Role::AfterBuild', 'Beam::Emitter';
10  
11 4 our @phases = ( ( map { my $phase = $_; ('before_'.$phase, $phase, 'after_'.$phase) } qw( install script ) ), 'after_success', 'after_failure' );
12 4 our @emptymvarrayattr = qw( notify_email notify_irc requires env script_env extra_dep apt_package );
13  
14 73 ▶has $_ => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [] } ) for (@phases, @emptymvarrayattr);
Subroutine __ANON__: called CC=1 SCAR=0.0
15  
16 4 our @bools = qw( verbose test_deps test_authordeps no_notify_email coveralls );
17  
18 25 ▶has $_ => ( is => 'ro', isa => 'Bool', default => sub { 0 } ) for @bools;
Subroutine __ANON__: called CC=1 SCAR=0.0
19  
20 5 ▶has irc_template => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [
Subroutine __ANON__: called CC=1 SCAR=0.0
21 5 "%{branch}#%{build_number} by %{author}: %{message} (%{build_url})",
22 4 ] } );
23  
24 5 ▶has perl_version => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [
Subroutine __ANON__: called CC=1 SCAR=0.0
25 5 "5.30",
26 "5.28",
27 "5.26",
28 "5.24",
29 "5.22",
30 "5.20",
31 "5.18",
32 "5.16",
33 "5.14",
34 4 ] } );
35  
36  
37 5 ▶has 'write_to' => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [ 'root' ] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 4 our @core_env = ("HARNESS_OPTIONS=j10:c HARNESS_TIMER=1");
40  
41 5 ▶around mvp_multivalue_args => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 5 my ($orig, $self) = @_;
43  
44 5 my @start = $self->$orig;
45 5 return @start, @phases, @emptymvarrayattr, qw( irc_template perl_version write_to );
46 4 };
47  
48 5 ▶sub gather_files {
Subroutine gather_files: called CC=2 SCAR=9.7
Pod undocumented
49 5 my $self = shift;
50 5 ▶ return unless grep { $_ eq 'build' } @{ $self->write_to };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "build";} @{$self->write_to;} 5 0 5
51 0 require YAML;
52 my $file = Dist::Zilla::File::FromCode->new(
53 name => '.travis.yml',
54 code_return_type => 'text', # YAML::Dump returns text
55 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 return $self->build_travis_yml_str;
57 },
58 0 );
59 0 $self->add_file($file);
60 0 return;
61 }
62  
63 5 ▶sub after_build {
Subroutine after_build: called CC=2 SCAR=7.0
Pod undocumented
64 5 my $self = shift;
65 5 ▶ return unless grep { $_ eq 'root' } @{ $self->write_to };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "root";} @{$self->write_to;} 0 5 5
66 5 path($self->zilla->root,'.travis.yml')->spew_utf8($self->build_travis_yml_str);
67 5 return;
68 }
69  
70 15 ▶sub _get_exports { shift; map { "export ".$_ } @_ }
Subroutine _get_exports: called CC=1 SCAR=0.0
71  
72 5 ▶sub build_travis_yml_str {
Subroutine build_travis_yml_str: called CC=1 SCAR=0.0
Pod undocumented
73 5 my ($self) = @_;
74 5 my $structure = $self->build_travis_yml;
75 5 require YAML;
76 5 local $YAML::QuoteNumericStrings=1;
77 5 return YAML::Dump($structure);
78 }
79  
80 5 ▶sub build_travis_yml {
Subroutine build_travis_yml: called CC=22 SCAR=35.3
Pod undocumented
81 5 my ($self, $is_build_branch) = @_;
82  
83 5 my $zilla = $self->zilla;
84 my %travisyml = (
85 language => "perl",
86 matrix => {
87 include => [ map {{
88 45 ▶ perl => sprintf('%.2f',$_),
Branch: 1 branch
BranchTrueFalseTotal
$_ <= 5.2 ? : 20 25 45
89 ( $_ <= 5.20 ) ? ( dist => "trusty" ) : (),
90 5 }} @{$self->perl_version} ]
91 }
92 );
93  
94 5 my $rmeta = $zilla->distmeta->{resources};
95  
96 5 my %notifications;
97  
98 0 my @emails = grep { $_ } @{$self->notify_email};
99 5 ▶ if ($self->no_notify_email) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->no_notify_email) { } 0 5 5
elsif (scalar @emails) { } 0 5 5
100 0 $notifications{email} = \"false";
101 } elsif (scalar @emails) {
102 0 $notifications{email} = \@emails;
103 }
104  
105 5 ▶ if (%notifications) {
Branch: 1 branch
BranchTrueFalseTotal
if (%notifications) 0 5 5
106 0 $travisyml{notifications} = \%notifications;
107 }
108  
109 5 ▶ if (@{$self->apt_package()}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->apt_package;}) 2 3 5
110 2 $travisyml{addons}->{apt_packages} = $self->apt_package();
111 }
112  
113 5 my %phases_commands = map { $_ => $self->$_ } @phases;
114  
115 5 ▶ my $verbose = $self->verbose ? ' --verbose ' : ' --quiet ';
Branch: 1 branch
BranchTrueFalseTotal
$self->verbose ? : 0 5 5
116  
117 5 unshift @{$phases_commands{before_install}}, (
118 'git config --global user.name "Dist Zilla Plugin TravisCI"',
119 'git config --global user.email $HOSTNAME":not-for-mail@travis-ci.com"',
120 );
121  
122 5 my @extra_deps = @{$self->extra_dep};
123  
124 5 my $needs_cover;
125  
126 5 ▶ if ($self->coveralls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->coveralls) 0 5 5
127 0 push @extra_deps, 'Devel::Cover::Report::Coveralls';
128 0 unshift @{$phases_commands{after_success}}, 'cover -report coveralls';
129 0 $needs_cover = 1;
130 }
131  
132 5 ▶ if ($needs_cover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($needs_cover) 0 5 5
133 0 push @{$self->env}, 'HARNESS_PERL_SWITCHES=-MDevel::Cover=-db,$TRAVIS_BUILD_DIR/cover_db';
134 }
135  
136 5 my @env_exports = $self->_get_exports(@core_env, @{$self->env});
137  
138 5 ▶ unless (@{$phases_commands{install}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$phases_commands{"install"};}) 5 0 5
139 5 ▶ push @{$phases_commands{install}}, (
Branch: 2 branches
BranchTrueFalseTotal
$self->test_authordeps ? : 0 5 5
$self->test_deps ? : 0 5 5
140 "cpanm ".$verbose." --notest --skip-installed Dist::Zilla",
141 "dzil authordeps | grep -ve '^\\W' | xargs -n 5 -P 10 cpanm ".$verbose." ".($self->test_authordeps ? "" : " --notest ")." --skip-installed",
142 "dzil listdeps | grep -ve '^\\W' | cpanm ".$verbose." ".($self->test_deps ? "" : " --notest ")." --skip-installed",
143 );
144 5 ▶ if (@extra_deps) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra_deps) 0 5 5
145 0 ▶ push @{$phases_commands{install}}, (
Branch: 1 branch
BranchTrueFalseTotal
$self->test_deps ? : 0 0 0
146 "cpanm ".$verbose." ".($self->test_deps ? "" : " --notest ")." ".join(" ",@extra_deps),
147 );
148 }
149 }
150  
151 5 ▶ unless (@{$phases_commands{script}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$phases_commands{"script"};}) 5 0 5
152 5 push @{$phases_commands{script}}, "dzil smoke --release --author";
153 }
154  
155 5 unshift @{$phases_commands{script}}, $self->_get_exports(@{$self->script_env});
156  
157 5 ▶ unless (@{$phases_commands{install}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$phases_commands{"install"};}) 0 5 5
158 $phases_commands{install} = [
159 0 ▶ 'cpanm --installdeps '.$verbose.' '.($self->test_deps ? "" : "--notest").' --skip-installed .',
Branch: 1 branch
BranchTrueFalseTotal
$self->test_deps ? : 0 0 0
160 ];
161 }
162  
163 5 ▶ if (@{$self->requires}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->requires;}) 0 5 5
164 0 unshift @{$phases_commands{before_install}}, "sudo apt-get install -qq ".join(" ",@{$self->requires});
165 }
166  
167 5 push @{$phases_commands{install}}, @{delete $phases_commands{after_install}};
168  
169 5 unshift @{$phases_commands{script}}, $self->_get_exports(@{$self->script_env});
170  
171 5 my $first = 0;
172 5 for (@phases) {
173 40 ▶ next unless defined $phases_commands{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $phases_commands{$_} 5 35 40
174 35 my @commands = @{$phases_commands{$_}};
175 35 ▶ if (@commands) {
Branch: 1 branch
BranchTrueFalseTotal
if (@commands) 15 20 35
176 15 ▶ $travisyml{$_} = [
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 10 5 15
177 $first
178 ? ()
179 : (@env_exports),
180 @commands,
181 ];
182 15 $first = 1;
183 }
184 }
185  
186 5 return $self->emit(
187 'modify_travis_yml',
188 class => 'Dist::Zilla::Event::TravisCI::YML',
189 travis_yml => { $self->modify_travis_yml(%travisyml) }
190 )->travis_yml;
191 }
192  
193 4 ▶sub modify_travis_yml {
Subroutine modify_travis_yml: called CC=1 SCAR=0.0
Pod documented
194 4 my ( $self, %args ) = @_;
195 4 return %args;
196 }
197  
198 4 __PACKAGE__->meta->make_immutable;
199  
200 package # Hidden
201 Dist::Zilla::Event::TravisCI::YML;
202  
203 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
204 4 extends 'Beam::Event';
205  
206 4 has 'travis_yml' => ( is => 'rw', isa => 'HashRef', required => 1 );
207  
208 4 __PACKAGE__->meta->make_immutable;
209  
210 4 1;
211  
212 __END__
↑ Summary