File Coverage

blib/lib/Dist/Zilla/Plugin/if/not/ENV.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1 3     3   4211740 use 5.006; # our
  3         7  
2 3     3   15 use strict;
  3         7  
  3         78  
3 3     3   13 use warnings;
  3         4  
  3         266  
4              
5             package Dist::Zilla::Plugin::if::not::ENV;
6              
7             our $VERSION = '0.001001';
8              
9             # ABSTRACT: Load a plugin when an ENV key is NOT true.
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 3     3   507 use Moose qw( has around with );
  3         290585  
  3         27  
14 3     3   13703 use Dist::Zilla::Util qw();
  3         8846  
  3         628  
15             with 'Dist::Zilla::Role::PluginLoader::Configurable';
16              
17             has key => ( is => ro =>, required => 1 );
18              
19             around dump_config => sub {
20             my ( $orig, $self, @args ) = @_;
21             my $config = $self->$orig(@args);
22             my $localconf = $config->{ +__PACKAGE__ } = {};
23              
24             $localconf->{key} = $self->key;
25              
26             $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
27             unless __PACKAGE__ eq ref $self;
28              
29             return $config;
30             };
31              
32             around load_plugins => sub {
33             my ( $orig, $self, $loader ) = @_;
34             my $key = $self->key;
35             return if exists $ENV{$key} and $ENV{$key};
36             return $self->$orig($loader);
37             };
38              
39             __PACKAGE__->meta->make_immutable;
40 3     3   16 no Moose;
  3         5  
  3         14  
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Dist::Zilla::Plugin::if::not::ENV - Load a plugin when an ENV key is NOT true.
53              
54             =head1 VERSION
55              
56             version 0.001001
57              
58             =head1 SYNOPSIS
59              
60             [if::not::ENV]
61             key = AIRPLANE
62             dz_plugin = Some::Plugin
63             dz_plugin_name = NOTAIRPLANE/Some::Plugin
64             >= some_plugin_argument = itsvalue
65             >= some_plugin_argument = itsvalue
66              
67             Then
68              
69             dzil build # Some::Plugin is loaded
70             AIRPLANE=1 dzil build # Some::Plugin NOT loaded!... but still a develop dep.
71             AIRPLANE=0 dzil build # Some::Plugin loaded
72              
73             =head2 SEE ALSO
74              
75             =over 4
76              
77             =item * C<[if]> - L<< Dist::Zilla::Plugin::if|Dist::Zilla::Plugin::if >>
78              
79             =item * C<[if::not]> - L<< Dist::Zilla::Plugin::if::not|Dist::Zilla::Plugin::if::not >>
80              
81             =item * C<[if::ENV]> - L<< Dist::Zilla::Plugin::if::ENV|Dist::Zilla::Plugin::if::ENV >>
82              
83             =item * C<PluginLoader::Configurable role> - L<<
84             Dist::Zilla::Role::PluginLoader::Configurable|Dist::Zilla::Role::PluginLoader::Configurable
85             >>
86              
87             =item * C<PluginLoader role> - L<< Dist::Zilla::Role::PluginLoader|Dist::Zilla::Role::PluginLoader >>
88              
89             =item * C<PluginLoader util> - L<< Dist::Zilla::Util::PluginLoader|Dist::Zilla::Util::PluginLoader >>
90              
91             =back
92              
93             =head1 AUTHOR
94              
95             Kent Fredric <kentnl@cpan.org>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
100              
101             This is free software; you can redistribute it and/or modify it under
102             the same terms as the Perl 5 programming language system itself.
103              
104             =cut