File Coverage

blib/lib/Dist/Zilla/Plugin/Test/CheckDeps.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 11 12 91.6


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Test::CheckDeps; # git description: v0.013-8-g41c9a1a
2             # vim: set ts=8 sts=4 sw=4 tw=115 et :
3              
4             our $VERSION = '0.014';
5              
6 3     3   1386709 use Moose;
  3         5  
  3         15  
7             extends qw/Dist::Zilla::Plugin::InlineFiles/;
8             with qw/Dist::Zilla::Role::TextTemplate Dist::Zilla::Role::PrereqSource/;
9 3     3   11583 use namespace::autoclean;
  3         3  
  3         17  
10              
11             has todo_when => (
12             is => 'ro',
13             isa => 'Str',
14             default => '0', # special value for 'insert no special code at all'
15             );
16              
17             has fatal => (
18             is => 'ro',
19             isa => 'Bool',
20             default => 0,
21             );
22              
23             has level => (
24             is => 'ro',
25             isa => 'Str',
26             lazy => 1,
27             default => 'classic',
28             );
29              
30             has filename => (
31             is => 'ro',
32             isa => 'Str',
33             default => 't/00-check-deps.t',
34             );
35              
36             around dump_config => sub {
37             my $orig = shift;
38             my $self = shift;
39              
40             my $config = $self->$orig;
41              
42             $config->{+__PACKAGE__} = {
43             (map { $_ => $self->$_ } qw(todo_when level filename)),
44             fatal => $self->fatal ? 1 : 0,
45             blessed($self) ne __PACKAGE__ ? ( version => $VERSION ) : (),
46             };
47              
48             return $config;
49             };
50              
51             around add_file => sub {
52             my ($orig, $self, $file) = @_;
53              
54             return $self->$orig(
55             Dist::Zilla::File::InMemory->new(
56             name => $self->filename,
57             content => $self->fill_in_string($file->content,
58             {
59             dist => \($self->zilla),
60             plugin => \$self,
61             todo_when => $self->todo_when,
62             fatal => $self->fatal,
63             level => $self->level,
64             })
65             )
66             );
67             };
68              
69             sub register_prereqs {
70 3     3 0 12043 my $self = shift;
71 3         77 $self->zilla->register_prereqs(
72             { phase => 'test', type => 'requires' },
73             'Test::More' => '0.94',
74             'Test::CheckDeps' => '0.010',
75             );
76             }
77              
78             __PACKAGE__->meta->make_immutable;
79              
80             # ABSTRACT: Check for presence of dependencies
81              
82             #pod =pod
83             #pod
84             #pod =head1 SYNOPSIS
85             #pod
86             #pod [Test::CheckDeps]
87             #pod fatal = 0 ; default
88             #pod level = classic
89             #pod
90             #pod =head1 DESCRIPTION
91             #pod
92             #pod This module adds a test that assures all dependencies have been installed properly. If requested, it can bail out all testing on error.
93             #pod
94             #pod This plugin accepts the following options:
95             #pod
96             #pod =for stopwords TODO
97             #pod
98             #pod =over 4
99             #pod
100             #pod =item * C<todo_when>: a code string snippet (evaluated when the test is run)
101             #pod to indicate when failing tests should be considered L<TODO|Test::More/Conditional tests>,
102             #pod rather than genuine fails -- default is '0' (tests are never C<TODO>).
103             #pod
104             #pod Other suggested values are:
105             #pod
106             #pod todo_when = !$ENV{AUTHOR_TESTING} && !$ENV{AUTOMATED_TESTING}
107             #pod todo_when = $^V < '5.012' ; CPAN.pm didn't reliably read META.* before this
108             #pod
109             #pod =item * C<fatal>: if true, C<BAIL_OUT> is called if the tests fail. Defaults
110             #pod to false.
111             #pod
112             #pod =item * C<level>: passed to C<check_dependencies> in L<Test::CheckDeps>.
113             #pod (Defaults to C<classic>.)
114             #pod
115             #pod =item * C<filename>: the name of the generated file. Defaults to
116             #pod F<t/00-check-deps.t>.
117             #pod
118             #pod =back
119             #pod
120             #pod =for Pod::Coverage register_prereqs
121             #pod
122             #pod =cut
123              
124             =pod
125              
126             =encoding UTF-8
127              
128             =head1 NAME
129              
130             Dist::Zilla::Plugin::Test::CheckDeps - Check for presence of dependencies
131              
132             =head1 VERSION
133              
134             version 0.014
135              
136             =head1 SYNOPSIS
137              
138             [Test::CheckDeps]
139             fatal = 0 ; default
140             level = classic
141              
142             =head1 DESCRIPTION
143              
144             This module adds a test that assures all dependencies have been installed properly. If requested, it can bail out all testing on error.
145              
146             This plugin accepts the following options:
147              
148             =for stopwords TODO
149              
150             =over 4
151              
152             =item * C<todo_when>: a code string snippet (evaluated when the test is run)
153             to indicate when failing tests should be considered L<TODO|Test::More/Conditional tests>,
154             rather than genuine fails -- default is '0' (tests are never C<TODO>).
155              
156             Other suggested values are:
157              
158             todo_when = !$ENV{AUTHOR_TESTING} && !$ENV{AUTOMATED_TESTING}
159             todo_when = $^V < '5.012' ; CPAN.pm didn't reliably read META.* before this
160              
161             =item * C<fatal>: if true, C<BAIL_OUT> is called if the tests fail. Defaults
162             to false.
163              
164             =item * C<level>: passed to C<check_dependencies> in L<Test::CheckDeps>.
165             (Defaults to C<classic>.)
166              
167             =item * C<filename>: the name of the generated file. Defaults to
168             F<t/00-check-deps.t>.
169              
170             =back
171              
172             =for Pod::Coverage register_prereqs
173              
174             =head1 SUPPORT
175              
176             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-Test-CheckDeps>
177             (or L<bug-Dist-Zilla-Plugin-Test-CheckDeps@rt.cpan.org|mailto:bug-Dist-Zilla-Plugin-Test-CheckDeps@rt.cpan.org>).
178              
179             There is also a mailing list available for users of this distribution, at
180             L<http://dzil.org/#mailing-list>.
181              
182             There is also an irc channel available for users of this distribution, at
183             L<C<#distzilla> on C<irc.perl.org>|irc://irc.perl.org/#distzilla>.
184              
185             =head1 AUTHOR
186              
187             Leon Timmermans <leont@cpan.org>
188              
189             =head1 CONTRIBUTORS
190              
191             =for stopwords Karen Etheridge Leon Timmermans Brendan Byrd
192              
193             =over 4
194              
195             =item *
196              
197             Karen Etheridge <ether@cpan.org>
198              
199             =item *
200              
201             Leon Timmermans <fawaka@gmail.com>
202              
203             =item *
204              
205             Brendan Byrd <GitHub@ResonatorSoft.org>
206              
207             =back
208              
209             =head1 COPYRIGHT AND LICENCE
210              
211             This software is copyright (c) 2011 by Leon Timmermans.
212              
213             This is free software; you can redistribute it and/or modify it under
214             the same terms as the Perl 5 programming language system itself.
215              
216             =cut
217              
218             __DATA__
219             ___[ test-checkdeps ]___
220             use strict;
221             use warnings;
222              
223             # this test was generated with {{ ref $plugin }} {{ $plugin->VERSION }}
224              
225             use Test::More 0.94;
226             {{
227             my $use = 'use Test::CheckDeps 0.010;';
228              
229             # todo_when = 0 is treated as a special default, backwards-compatible case
230             $use = "BEGIN {\n ($todo_when) && eval \"" . $use
231             . " 1\"\n or plan skip_all => '!!! Test::CheckDeps required for checking dependencies -- failure to satisfy specified prerequisites!';\n}\n"
232             . $use
233             if $todo_when ne '0';
234             $use
235             }}
236              
237             {{
238             $todo_when eq '0'
239             ? ''
240             : "local \$TODO = 'these tests are not fatal when $todo_when' if (${todo_when});\n"
241             . 'my $builder = Test::Builder->new;' . "\n"
242             . 'my $todo_output_orig = $builder->todo_output;' . "\n"
243             . '$builder->todo_output($builder->failure_output);' . "\n";
244             }}
245             check_dependencies('{{ $level }}');
246             {{
247             $todo_when ne '0' ? "\$builder->todo_output(\$todo_output_orig);\n" : '';
248             }}
249              
250             if ({{ $fatal }}) {
251             BAIL_OUT("Missing dependencies") if !Test::More->builder->is_passing;
252             }
253              
254             done_testing;