Dist/Zilla/PluginBundle/Author/IOANR.pm

filter: Statementstmt 32.9% 27 / 82 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 23.5% 4 / 17 Podpod 33.3% 1 / 3 totaltotal 23.8% 32 / 134 CC 15 SCAR 28.3
CC
15
Cov
24%
configure
42.0
_build_release_plugins
30.0
_build__resources
20.0
CRAP 16.9
↑ Summary Pod/Weaver/PluginBundle/Author/IOANR.pm »
1 package Dist::Zilla::PluginBundle::Author::IOANR 1.230480;
2  
3 # ABSTRACT: Build dists the way IOANR likes
4  
5 1 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use List::Util 1.33 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Git::Wrapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 with 'Dist::Zilla::Role::PluginBundle::Easy';
11  
12 # TODO optionally add OSPreqs
13 # TODO Test::MinimumVersion - plugin generated test only checks META.yml, which we don't have
14  
15 # plugins required to make a release, not neccessarily
16 # ones that *do* DZR::Releaser
17 1 has release_plugins => (is => 'ro', lazy_build => 1);
18  
19 has autogenerated_files => (
20 is => 'ro',
21 lazy => 1,
22 0 ▶ default => sub { [qw/README.md Changes LICENSE/] });
Subroutine __ANON__: not called CC=1 SCAR=1.2
23  
24 has allow_dirty_files => (
25 is => 'ro',
26 lazy => 1,
27 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 [$_[0]->autogenerated_files->@*, 'dist.ini',];
29 },
30 1 );
31  
32 # XXX can I get this from $zilla somehow? Maybe a custom plugin?
33 1 has dist_name => (is => 'ro', predicate => 'has_dist_name');
34 1 has git_remote => (is => 'ro', default => 'origin');
35  
36 0 ▶has _git => (is => 'ro', lazy =>1, default => sub { Git::Wrapper->new('.') });
Subroutine __ANON__: not called CC=1 SCAR=1.2
37 1 has major_version => (
38 is => 'ro',
39 default => 0,
40 );
41  
42 has fake_release => (
43 is => 'ro',
44 lazy => 1,
45 0 ▶ default => sub { $ENV{DZIL_FAKE_RELEASE} // 0 },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$ENV{"DZIL_FAKE_RELEASE"} // 0
l!l
00
MC/DC0%0/1
$ENV{"DZIL_FAKE_RELEASE"} // 0
$ENV{"DZIL_FAKE_RELEASE"}
Truth table0%0/2
A
A= $ENV{"DZIL_FAKE_RELEASE"}
Aresult
11
00
46 1 );
47  
48 1 has semantic_version => (
49 is => 'ro',
50 default => 0,
51 );
52  
53 has assert_os => (
54 is => 'ro',
55 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 1 );
57  
58 has disable => (
59 is => 'ro',
60 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 1 );
62  
63 1 has _resources => (
64 is => 'ro',
65 isa => 'HashRef',
66 lazy_build => 1,
67 );
68  
69 0 ▶sub BUILDARGS {
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
70 0 my ($orig, $class, @args) = @_;
71 # use the payload as attrs
72 0 return { $class->{payload}->%*, $class->%* };
73 }
74  
75 # try to work out metadata resources from the git remote
76 # totally falls apart if not using git, only works with gitlab and github,
77 # and relies on the urls being much the same
78 0 ▶sub _build__resources {
Subroutine _build__resources: not called CC=4 SCAR=30.0
79 0 my $self = shift;
80  
81 # this will totally fall apart
82 0 my @remote = $self->_git->remote(qw/get-url/, $self->git_remote);
83 0 my $git_url = shift @remote;
84 0 ▶ if (!$git_url) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($git_url) 0 0 0
85 0 die "Failed to find git remote url\n";
86 }
87  
88 0 my ($git_host, $git_org, $git_repo) = $git_url =~ m{^.+@?(github|gitlab).com[:/](\w+)/(.+)(\.git)?$};
89 0 ▶ if (!$git_host) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($git_host) 0 0 0
90 0 die "Unable to find supported git host from $git_url\n";
91 }
92  
93 # sometimes dist name and repo/project name are the same, sometimes the repo
94 # has a p5- prefix
95 0 ▶ my $dist_name = $self->has_dist_name ? $self->dist_name : $git_repo;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_dist_name ? : 0 0 0
96 0 my $resources = {
97 'bugtracker.web' => sprintf('https://%s.com/%s/%s/issues', $git_host, $git_org, $git_repo),
98 'homepage' => sprintf('https://metacpan.org/release/%s', $dist_name),
99 'repository.type' => 'git',
100 'repository.url' => sprintf('https://%s.com/%s/%s.git', $git_host, $git_org, $git_repo),
101 'repository.web' => sprintf('https://%s.com/%s/%s', $git_host, $git_org, $git_repo),
102 };
103  
104 0 return $resources;
105 }
106  
107 0 ▶sub _build_release_plugins {
Subroutine _build_release_plugins: not called CC=5 SCAR=34.0
108 0 my $self = shift;
109  
110 0 my @release_plugins = (qw/TestRelease/);
111  
112 # do not allow any release to be made without the git plugins
113 0 ▶ if ($ENV{DZIL_NO_GIT_LOCAL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"DZIL_NO_GIT_LOCAL"}) 0 0 0
114 0 return [@release_plugins, 'FakeRelease'];
115 }
116  
117 # nothing further should happen without confirmation
118 0 push @release_plugins, 'ConfirmRelease';
119  
120 # add plugins which make LOCAL REPO ONLY changes to git
121 0 push @release_plugins,
122 ['Git::Commit' => {allow_dirty => $self->allow_dirty_files}],
123 [
124 'Git::CommitBuild' => {
125 branch => '',
126 release_branch => 'release',
127 release_message => 'Release %v',
128 multiple_inheritance => 1,
129 }
130 ],
131 ['Git::Tag' => {signed => 1, branch => 'release'}];
132  
133 # add plugins which affect remote git remotes
134 0 ▶ unless ($ENV{DZIL_NO_GIT_REMOTE}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"DZIL_NO_GIT_REMOTE"}) 0 0 0
135 0 push @release_plugins, 'Git::Push';
136 }
137  
138 # DO NOT allow making a release to CPAN that isn't also pushed to remote git
139 # DO allow making remote git changes without a CPAN release as it's easy to undo
140 # and is useful for testing plugin settings
141 0 ▶ if ($self->fake_release || $ENV{DZIL_NO_GIT_REMOTE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fake_release or $ENV{'DZIL_NO_GIT_REMOTE'}) { } 0 0 0
Condition0%0/3
$self->fake_release or $ENV{"DZIL_NO_GIT_REMOTE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->fake_release or $ENV{"DZIL_NO_GIT_REMOTE"}
$self->fake_release $ENV{"DZIL_NO_GIT_REMOTE"}
Truth table0%0/3
A or B
A= $self->fake_releaseB= $ENV{"DZIL_NO_GIT_REMOTE"}
ABresult
1X1
011
000
142 0 push @release_plugins, 'FakeRelease';
143 } else {
144 0 push @release_plugins, 'UploadToCPAN';
145 }
146  
147 0 return \@release_plugins;
148 }
149  
150 has build_plugin => (
151 is => 'ro',
152 lazy => 1,
153 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
154 0 ▶ if ($_[0]->payload->{custom_builder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]->payload->{'custom_builder'}) { } 0 0 0
155 0 return [ModuleBuild => {mb_class => 'My::Builder'}];
156 } else {
157  
158 # TODO add an option to handle experimental statis installs
159 # https://metacpan.org/pod/Dist::Zilla::Plugin::ModuleBuildTiny#static
160 0 return 'ModuleBuildTiny';
161 }
162 1 });
163  
164 0 ▶sub mvp_multivalue_args {qw/disable assert_os/}
Subroutine mvp_multivalue_args: not called CC=1 SCAR=6.9
Pod undocumented
165  
166 0 ▶sub configure {
Subroutine configure: not called CC=6 SCAR=37.4
Pod undocumented
167 0 my ($self) = @_;
168  
169 0 my $change_opts = {
170 exclude_message => '^(dist.ini|v(\d+\.?)+)',
171 edit_changelog => 1,
172 };
173  
174 0 ▶ if ($self->semantic_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->semantic_version) 0 0 0
175 0 $change_opts->{tag_regexp} = 'semantic';
176 }
177  
178 0 ▶ if ($ENV{V}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'V'}) { } 0 0 0
179 0 $self->add_plugins([AutoVersion => {format => q<{{ $ENV{V} }}>}]);
180 } else {
181 0 $self->add_plugins([AutoVersion => {major => $self->major_version}]);
182 }
183  
184 0 $self->add_plugins([MetaResources => $self->_resources]);
185  
186 0 my @plugins = (
187 'AutoPrereqs',
188 ['ChangelogFromGit::CPAN::Changes' => $change_opts],
189 'ContributorsFile',
190 ['Git::Contributors' => {order_by => 'commits'}],
191 ['CopyFilesFromBuild' => {copy => $self->autogenerated_files}],
192 'ExecDir',
193 [
194 'Git::Check' => {
195 allow_dirty => $self->allow_dirty_files,
196 build_warnings => 1,
197 untracked_files => 'warn',
198 }
199 ],
200 [
201 'Git::GatherDir' => {
202 include_dotfiles => 1,
203 exclude_filename => $self->autogenerated_files,
204 }
205 ],
206 'License',
207 'Manifest',
208 ['MetaData::BuiltWith' => {show_config => 1}],
209 'MetaJSON',
210 ['PodWeaver' => {config_plugin => '@Author::IOANR'}],
211 ['PkgVersion' => {use_package => 1}],
212 'Prereqs::AuthorDeps',
213 'PruneCruft',
214 ['ReadmeAnyFromPod' => {type => 'gfm', location => 'build'}],
215 'ShareDir',
216 'Signature',
217 'MojibakeTests',
218 'AuthorSignatureTest',
219 'Test::CheckDeps',
220 'Test::Compile',
221 'Test::EOL',
222 ['Test::Kwalitee' => {skiptest => [qw/has_readme/]}],
223 'Test::NoTabs',
224 'Test::Pod::No404s',
225 'Test::Portability',
226 'Test::ReportPrereqs',
227 'Test::UnusedVars',
228 'Test::Synopsis',
229 'Test::Version',
230 );
231  
232 # Test::Perl::Critic
233 # PodCoverageTests
234 # PodSyntaxTests
235  
236 0 push @plugins, $self->release_plugins->@*;
237 0 my @add;
238 0 ▶ while (my $p = shift @plugins) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = shift @plugins) 0 0 0
239 0 ▶ next if any { $_ eq $p } $self->disable->@*;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $_ eq $p; } , @{$self->disable}) 0 0 0
240 0 push @add, $p;
241 }
242  
243 0 push @add, $self->build_plugin;
244  
245 # these have to come after the builder
246 # push @add, 'RunExtraTests';
247  
248 0 ▶ if ($self->assert_os->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->assert_os}) 0 0 0
249 0 push @add, [AssertOS => { os => $self->assert_os, bundle => 0 }];
250 }
251  
252 0 $self->add_plugins(@add);
253  
254 0 return;
255 }
256  
257 1 __PACKAGE__->meta->make_immutable;
258 1 1;
259  
260 __END__
↑ Summary Pod/Weaver/PluginBundle/Author/IOANR.pm »