File Coverage

blib/lib/Dist/Zilla/Plugin/MakeMaker/ApacheTest.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::MakeMaker::ApacheTest;
2             $Dist::Zilla::Plugin::MakeMaker::ApacheTest::VERSION = '0.04';
3             # ABSTRACT: Dist::Zilla Plugin That Configures Makefile.PL for Apache::Test
4              
5 1     1   560 use Moose;
  1         2  
  1         4  
6              
7             extends 'Dist::Zilla::Plugin::MakeMaker::Awesome';
8              
9             # the minimum version of Apache::Test that is required.
10             has min_version => (
11             is => 'ro',
12             isa => 'Str',
13             default => sub { 0 });
14              
15              
16             around _build_header => sub {
17             my ($orig, $self) = splice @_, 0, 2;
18              
19             my $header = $self->$orig(@_);
20              
21             return $header . <<'END';
22             # figure out if mod_perl v1 or v2 is installed. DynamicPrereqs in the
23             # PluginBundle needs this to require the appropriate mod_perl module.
24             my $mp_version = mod_perl_version();
25              
26             # configure Apache::Test
27             test_configure();
28             END
29             };
30              
31             around register_prereqs => sub {
32             my ($orig, $self) = splice @_, 0, 2;
33              
34             my $res = $self->$orig(@_);
35              
36             $self->zilla->register_prereqs(
37             { phase => 'configure' },
38             'Apache::Test' => $self->min_version
39             );
40              
41             return $res;
42             };
43              
44             # DZP::MakeMaker::Awesome does not have a hook for clean_files, so we have to
45             # munge the WriteMakefile args instead.
46             around _build_WriteMakefile_args => sub {
47             my ($orig, $self) = splice @_, 0, 2;
48              
49             my $args = $self->$orig(@_);
50              
51             $args->{clean} ||= {};
52             $args->{clean}{FILES} ||= [];
53              
54             push @{ $args->{clean}{FILES} }, 't/TEST';
55              
56             return $args;
57             };
58              
59             around _build_footer => sub {
60             my ($orig, $self) = splice @_, 0, 2;
61              
62             my $text = $self->$orig(@_);
63              
64             $text .= <<'END';
65             sub test_configure {
66             require Apache::TestMM;
67              
68             # enable make test
69             Apache::TestMM->import(qw(test clean));
70              
71             Apache::TestMM::filter_args();
72              
73             Apache::TestMM::generate_script('t/TEST');
74             }
75              
76             sub mod_perl_version {
77             # try MP2
78             eval {
79             require mod_perl2;
80             };
81             unless ($@) {
82             return 2;
83             }
84              
85             # try MP1
86             eval {
87             require mod_perl;
88             };
89             unless ($@) {
90             if ($mod_perl::VERSION >= 1.99) {
91             # mod_perl 2, prior to the mod_perl2 rename (1.99_21, AKA 2.0.0 RC5)
92             die "mod_perl 2.0 RC5 or later is required\n";
93             }
94              
95             return 1;
96             }
97              
98             # assume mod_perl version 2 is wanted
99             return 2;
100             }
101             END
102              
103             return $text;
104             };
105              
106             __PACKAGE__->meta->make_immutable;
107 1     1   5856 no Moose;
  1         3  
  1         4  
108             1;
109              
110             __END__
111              
112             =pod
113              
114             =head1 NAME
115              
116             Dist::Zilla::Plugin::MakeMaker::ApacheTest - Dist::Zilla Plugin That Configures Makefile.PL for Apache::Test
117              
118             =head1 VERSION
119              
120             version 0.04
121              
122             =head1 SYNOPSIS
123              
124             You problably don't want to use this plugin directly. You probably want
125             the plugin bundle L<ApacheTest|Dist::Zilla::PluginBundle::ApacheTest> instead.
126              
127             =head1 DESCRIPTION
128              
129             This plugin will produce an L<ExtUtils::MakeMaker>-powered F<Makefile.PL> with
130             L<Apache::Test> hooks for the distribution. If you use this plugin, you should
131             F<not> use the L<MakeMaker|Dist::Zilla::Plugin::MakeMaker> plugin.
132              
133             This module extends
134             L<MakeMaker::Awesome|Dist::Zilla::Plugin::MakeMaker::Awesome> to fill in the
135             necessary part of the Makefile.PL to enable L<Apache::Test>.
136              
137             =head1 CONFIGURATION OPTIONS
138              
139             The following options are avaliable in F<dist.ini> for this plugin:
140              
141             =over 4
142              
143             =item *
144              
145             min_version
146              
147             The minimum version of Apache::Test that will be required in C<Makefile.PL>.
148             The default is C<0>. You are B<strongly> encouraged to explicitly specify the
149             version of L<Apache::Test> that is required by your module instead of relying
150             on the default.
151              
152             =back
153              
154             =head1 SEE ALSO
155              
156             =over 4
157              
158             =item *
159              
160             L<MakeMaker::Awesome|Dist::Zilla::Plugin::MakeMaker::Awesome>
161              
162             =back
163              
164             =head1 SOURCE
165              
166             The development version is on github at L<https://github.com/mschout/dist-zilla-plugin-apachetest>
167             and may be cloned from L<git://github.com/mschout/dist-zilla-plugin-apachetest.git>
168              
169             =head1 BUGS
170              
171             Please report any bugs or feature requests to bug-dist-zilla-plugin-apachetest@rt.cpan.org or through the web interface at:
172             http://rt.cpan.org/Public/Dist/Display.html?Name=Dist-Zilla-Plugin-ApacheTest
173              
174             =head1 AUTHOR
175              
176             Michael Schout <mschout@cpan.org>
177              
178             =head1 COPYRIGHT AND LICENSE
179              
180             This software is copyright (c) 2017 by Michael Schout.
181              
182             This is free software; you can redistribute it and/or modify it under
183             the same terms as the Perl 5 programming language system itself.
184              
185             =cut