File Coverage

blib/lib/Dist/Zilla/Role/PluginBundle/Airplane.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition 4 5 80.0
subroutine 5 5 100.0
pod n/a
total 24 25 96.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Role::PluginBundle::Airplane;
2             our $VERSION = '0.002';
3 1     1   729608 use Moose::Role;
  1         10  
  1         8  
4              
5             # ABSTRACT: A role for building packages with Dist::Zilla in an airplane
6              
7 1     1   6233 use Dist::Zilla::Util;
  1         16962  
  1         337  
8              
9             requires 'build_network_plugins';
10              
11             has airplane => (
12             is => 'ro',
13             isa => 'Bool',
14             init_arg => undef,
15             lazy => 1,
16             builder => '_build_airplane_mode',
17             );
18              
19             has network_plugins => (
20             is => 'ro',
21             isa => 'ArrayRef',
22             init_arg => undef,
23             lazy => 1,
24             builder => 'build_network_plugins',
25             );
26              
27             sub _build_airplane_mode {
28 5   66 5   164 return $ENV{DZIL_AIRPLANE} // $_[0]->payload->{airplane} // 0;
      100        
29             }
30              
31             sub _get_network_plugins {
32 3     3   7 my ($self) = @_;
33              
34 3         7 my %network_plugins;
35 3         5 for (@{$self->network_plugins}) {
  3         113  
36 3         10 $network_plugins{$self->_plugin_to_name($_)} = 1;
37             }
38 3         112 return \%network_plugins;
39             }
40              
41             sub _plugin_to_name {
42 5     5   13 my ($self, $plugin) = @_;
43 5         21 return Dist::Zilla::Util->expand_config_package_name($plugin);
44             }
45              
46             around add_plugins => sub {
47             my $orig = shift;
48             my $self = shift;
49             my @plugins = @_;
50              
51              
52             if ($self->airplane) {
53             my $plugins = $self->_get_network_plugins();
54             @plugins = grep {
55             not exists $plugins->{
56             $self->_plugin_to_name(
57             !ref $_ ? $_ : ref eq 'ARRAY' ? $_->[0] : die "unable")
58             };
59             } @plugins;
60              
61              
62             # halt release after pre-release checks, but before ConfirmRelease
63             push @plugins, 'BlockRelease';
64             }
65              
66             $orig->($self, @plugins);
67             };
68              
69             1;
70              
71             __END__
72              
73             =pod
74              
75             =encoding UTF-8
76              
77             =head1 NAME
78              
79             Dist::Zilla::Role::PluginBundle::Airplane - A role for building packages with Dist::Zilla in an airplane
80              
81             =head1 VERSION
82              
83             version 0.002
84              
85             =head1 SYNOPSIS
86              
87             package Dist::Zilla::PluginBundle::Author::EXAMPLE;
88             use Moose;
89              
90             with 'Dist::Zilla::Role::PluginBundle::Airplane';
91              
92             # You are required to implement this method
93             sub build_network_plugins {
94             return [qw(
95             PromptIfStale
96             Test::Pod::LinkCheck
97             Test::Pod::No404s
98             Git::Remote::Check
99             CheckPrereqsIndexed
100             CheckIssues
101             UploadToCPAN
102             UploadToStratopan
103             Git::Push
104             )];
105             };
106              
107             sub configure {
108             my $self = shift;
109              
110             my @plugins = ['PromptIfStale'];
111              
112             $self->add_plugins(@plugins);
113             }
114              
115             =head1 DESCRIPTION
116              
117             Enables airplane mode for your dzil plugin bundle. This means all network
118             plugins are removed from loading and aborts a release via the plugin
119             L<Dist::Zilla::Plugin::BlockRelease>.
120              
121             # In your dist.ini
122             [@Author::EXAMPLE]
123             airplane = 1 ; or DZIL_AIRPLANE=1 in your shell
124              
125             =head1 AUTHOR
126              
127             Wesley Schwengle <waterkip@cpan.org>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             This software is Copyright (c) 2019 by Wesley Schwengle.
132              
133             This is free software, licensed under:
134              
135             The (three-clause) BSD License
136              
137             =cut