File Coverage

blib/lib/Dist/Zilla/Plugin/UseUnsafeInc.pm
Criterion Covered Total %
statement 20 20 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 3 0.0
total 32 36 88.8


line stmt bran cond sub pod time code
1 2     2   6121930 use strict;
  2         6  
  2         64  
2 2     2   9 use warnings;
  2         6  
  2         131  
3             package Dist::Zilla::Plugin::UseUnsafeInc; # git description: f69f5d2
4             # vim: set ts=8 sts=4 sw=4 tw=115 et :
5             # ABSTRACT: Indicates the value of PERL_USE_UNSAFE_INC to use during installation
6             # KEYWORDS: metadata PERL_USE_UNSAFE_inc distribution testing compatibility environment
7              
8             our $VERSION = '0.001';
9              
10 2     2   12 use Moose;
  2         4  
  2         64  
11             with 'Dist::Zilla::Role::MetaProvider',
12             'Dist::Zilla::Role::AfterBuild',
13             'Dist::Zilla::Role::BeforeRelease';
14              
15 2     2   12921 use namespace::autoclean;
  2         4  
  2         21  
16              
17             has dot_in_INC => (
18             is => 'ro', isa => 'Bool',
19             required => 1,
20             );
21              
22             around dump_config => sub
23             {
24             my ($orig, $self) = @_;
25             my $config = $self->$orig;
26              
27             $config->{+__PACKAGE__} = {
28             dot_in_INC => $self->dot_in_INC ? 1 : 0,
29             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
30             };
31              
32             return $config;
33             };
34              
35             sub metadata
36             {
37 4     4 0 81701 my $self = shift;
38 4 100       240 +{ x_use_unsafe_inc => $self->dot_in_INC ? 1 : 0 };
39             }
40              
41             sub after_build
42             {
43 4     4 0 215341 my $self = shift;
44              
45             # this is kind of kludgy but we just need to have this set before TestRunners run.
46 4         141 $self->log_debug([ 'Setting PERL_USE_UNSAFE_INC = %s for local testing...', $self->dot_in_INC ]);
47 4         1924 $ENV{PERL_USE_UNSAFE_INC} = $self->dot_in_INC;
48             }
49              
50             sub before_release
51             {
52 4     4 0 247493 my $self = shift;
53              
54             $self->log('DZIL_ANY_PERL set: skipping perl version check'), return
55 4 100       44 if $ENV{DZIL_ANY_PERL};
56              
57 2 50       33 $self->log_fatal('Perl must be 5.025007 or newer to test with PERL_USE_UNSAFE_INC -- disable check with DZIL_ANY_PERL=1')
58             if "$]" < 5.025007;
59             }
60              
61             __PACKAGE__->meta->make_immutable;
62              
63             __END__
64              
65             =pod
66              
67             =encoding UTF-8
68              
69             =head1 NAME
70              
71             Dist::Zilla::Plugin::UseUnsafeInc - Indicates the value of PERL_USE_UNSAFE_INC to use during installation
72              
73             =head1 VERSION
74              
75             version 0.001
76              
77             =head1 SYNOPSIS
78              
79             In your F<dist.ini>:
80              
81             ; this distribution still requires . to be in @INC
82             [UseUnsafeInc]
83             dot_in_INC = 1
84              
85             or:
86              
87             ; this distribution does not need . to be in @INC
88             [UseUnsafeInc]
89             dot_in_INC = 0
90              
91             =head1 DESCRIPTION
92              
93             =for Pod::Coverage metadata after_build before_release
94              
95             This is a L<Dist::Zilla> plugin that populates the C<x_use_unsafe_inc> key in your distribution metadata. This
96             indicates to components of the toolchain that C<PERL_USE_UNSAFE_INC> should be set to a certain value during
97             installation and testing, overriding any previous setting e.g. from the environment or from other tools.
98              
99             The environment variable is also set in L<Dist::Zilla> while building and testing the distribution, to ensure
100             that local testing behaves in an expected fashion.
101              
102             Additionally, the release must be performed using a Perl version that supports C<PERL_USE_UNSAFE_INC>, to further
103             guarantee test integrity.
104              
105             =head1 CONFIGURATION OPTIONS
106              
107             =head2 C<use_unsafe_inc>
108              
109             This configuration value must be set in your F<dist.ini>, to either 0 or 1. C<PERL_USE_UNSAFE_INC> will be set to
110             the same value by tools that support it.
111              
112             =head2 C<DZIL_ANY_PERL>
113              
114             When this environment variable is true, the Perl version check at release time (see above) is skipped.
115              
116             =head1 BACKGROUND
117              
118             =head1 SEE ALSO
119              
120             =over 4
121              
122             =item *
123              
124             L<perldelta/'.' and @INC>
125              
126             =back
127              
128             =head1 SUPPORT
129              
130             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-UseUnsafeInc>
131             (or L<bug-Dist-Zilla-Plugin-UseUnsafeInc@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-UseUnsafeInc@rt.cpan.org>).
132              
133             There is also a mailing list available for users of this distribution, at
134             L<http://dzil.org/#mailing-list>.
135              
136             There is also an irc channel available for users of this distribution, at
137             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
138              
139             I am also usually active on irc, as 'ether' at C<irc.perl.org>.
140              
141             =head1 AUTHOR
142              
143             Karen Etheridge <ether@cpan.org>
144              
145             =head1 COPYRIGHT AND LICENCE
146              
147             This software is copyright (c) 2017 by Karen Etheridge.
148              
149             This is free software; you can redistribute it and/or modify it under
150             the same terms as the Perl 5 programming language system itself.
151              
152             =cut