1# -*- mode: perl; c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 3use strict; 4use ExtUtils::MakeMaker qw(WriteMakefile); 5# See lib/ExtUtils/MakeMaker.pm for details of how to influence 6# the contents of the Makefile that is written. 7 8# Normalize version strings like 6.30_02 to 6.3002, 9# so that we can do numerical comparisons on it. 10my $eumm_version = $ExtUtils::MakeMaker::VERSION; 11$eumm_version =~ s/_//; 12 13my $module = 'Test::HTTP::LocalServer'; 14(my $main_file = "lib/$module.pm" ) =~ s!::!/!g; 15(my $distbase = $module) =~ s!::!-!g; 16my $distlink = $distbase; 17 18my @tests = map { glob $_ } 't/*.t', 't/*/*.t'; 19 20my %module = ( 21 MIN_PERL_VERSION => '5.008', 22 NAME => $module, 23 AUTHOR => q{Max Maischein <corion@cpan.org>}, 24 VERSION_FROM => $main_file, 25 ABSTRACT_FROM => $main_file, 26 META_MERGE => { 27 "meta-spec" => { version => 2 }, 28 resources => { 29 repository => { 30 web => "https://github.com/Corion/$distlink", 31 url => "git://github.com/Corion/$distlink.git", 32 type => 'git', 33 }, 34 bugtracker => "https://rt.cpan.org/Public/Dist/Display.html?Name=$distbase", 35 license => "https://dev.perl.org/licenses/", 36 }, 37 dynamic_config => 0, # we promise to keep META.* up-to-date 38 x_static_install => 1, # we are pure Perl and don't do anything fancy 39 }, 40 41 'LICENSE'=> 'perl', 42 43 PL_FILES => {}, 44 BUILD_REQUIRES => { 45 # Fairly long in core 46 'File::Path' => 0, 47 'File::Copy' => 0, 48 'File::Find' => 0, 49 'File::Basename' => 0, 50 'ExtUtils::MakeMaker' => 0, 51 }, 52 53 PREREQ_PM => { 54 'Carp' => 0, 55 'Getopt::Long' => 0, 56 'File::Spec' => 0, 57 'File::Temp' => 0, 58 'Cwd' => 0, 59 'File::Basename' => 0, 60 'HTTP::Response' => 0, 61 'HTTP::Daemon' => 6.05, 62 'HTTP::Tiny' => 0, 63 'IO::Socket::INET' => 0, # For port probing 64 'CGI' => 0, 65 'HTTP::Request::AsCGI' => 0, 66 'Socket' => 0, # for detecting 127.0.0.1 vs [::1] 67 'IO::Socket::IP' => 0.25, # for handling IPv6-only localhost 68 'URI' => 0, 69 'URI::URL' => 0, 70 'Time::HiRes' => 0, 71 }, 72 TEST_REQUIRES => { 73 'Test::More' => 0, 74 }, 75 76 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 77 clean => { FILES => "$distbase-*" }, 78 79 test => { TESTS => join( ' ', @tests ) }, 80); 81 82# This is so that we can do 83# require 'Makefile.PL' 84# and then call get_module_info 85 86sub get_module_info { %module } 87 88if( ! caller ) { 89 # I should maybe use something like Shipwright... 90 regen_README($main_file); 91 regen_EXAMPLES() if -d 'examples'; 92 WriteMakefile1(get_module_info); 93}; 94 951; 96 97sub WriteMakefile1 { #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade. 98 my %params=@_; 99 my $eumm_version=$ExtUtils::MakeMaker::VERSION; 100 $eumm_version=eval $eumm_version; 101 die "EXTRA_META is deprecated" if exists $params{EXTRA_META}; 102 die "License not specified" if not exists $params{LICENSE}; 103 if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) { 104 #EUMM 6.5502 has problems with BUILD_REQUIRES 105 $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} }; 106 delete $params{BUILD_REQUIRES}; 107 } 108 if ($params{TEST_REQUIRES} and $eumm_version < 6.64) { 109 $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{TEST_REQUIRES}} }; 110 delete $params{TEST_REQUIRES}; 111 } 112 delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52; 113 delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48; 114 delete $params{META_MERGE} if $eumm_version < 6.46; 115 delete $params{META_ADD} if $eumm_version < 6.46; 116 delete $params{LICENSE} if $eumm_version < 6.31; 117 delete $params{AUTHOR} if $] < 5.005; 118 delete $params{ABSTRACT_FROM} if $] < 5.005; 119 delete $params{BINARY_LOCATION} if $] < 5.005; 120 121 WriteMakefile(%params); 122} 123 124sub regen_README { 125 # README is the short version that just tells people what this is 126 # and how to install it 127 eval { 128 # Get description 129 my $readme = join "\n", 130 pod_section($_[0], 'NAME', 'no heading' ), 131 pod_section($_[0], 'DESCRIPTION' ), 132 <<INSTALL, 133 134INSTALLATION 135 136This is a Perl module distribution. It should be installed with whichever 137tool you use to manage your installation of Perl, e.g. any of 138 139 cpanm . 140 cpan . 141 cpanp -i . 142 143Consult https://www.cpan.org/modules/INSTALL.html for further instruction. 144Should you wish to install this module manually, the procedure is 145 146 perl Makefile.PL 147 make 148 make test 149 make install 150 151INSTALL 152 pod_section($_[0], 'REPOSITORY'), 153 pod_section($_[0], 'SUPPORT'), 154 pod_section($_[0], 'TALKS'), 155 pod_section($_[0], 'KNOWN ISSUES'), 156 pod_section($_[0], 'BUG TRACKER'), 157 pod_section($_[0], 'CONTRIBUTING'), 158 pod_section($_[0], 'SEE ALSO'), 159 pod_section($_[0], 'AUTHOR'), 160 pod_section($_[0], 'LICENSE' ), 161 pod_section($_[0], 'COPYRIGHT' ), 162 ; 163 update_file( 'README', $readme ); 164 }; 165 # README.mkdn is the documentation that will be shown as the main 166 # page of the repository on Github. Hence we recreate the POD here 167 # as Markdown 168 eval { 169 require Pod::Markdown; 170 171 my $parser = Pod::Markdown->new(); 172 173 # Read POD from Module.pm and write to README 174 $parser->parse_from_file($_[0]); 175 my $readme_mkdn = <<STATUS . $parser->as_markdown; 176 177[![Travis Build Status](https://travis-ci.org/Corion/$distlink.svg?branch=master)](https://travis-ci.org/Corion/$distlink) 178[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/Corion/$distlink?branch=master&svg=true)](https://ci.appveyor.com/project/Corion/$distlink) 179 180STATUS 181 update_file( 'README.mkdn', $readme_mkdn ); 182 }; 183} 184 185sub pod_section { 186 my( $filename, $section, $remove_heading ) = @_; 187 open my $fh, '<', $filename 188 or die "Couldn't read '$filename': $!"; 189 190 my @section = 191 grep { /^=head1\s+$section/.../^=/ } <$fh>; 192 193 # Trim the section 194 if( @section ) { 195 pop @section if $section[-1] =~ /^=/; 196 shift @section if $remove_heading; 197 198 pop @section 199 while @section and $section[-1] =~ /^\s*$/; 200 shift @section 201 while @section and $section[0] =~ /^\s*$/; 202 }; 203 204 @section = map { $_ =~ s!^=\w+\s+!!; $_ } @section; 205 return join "", @section; 206} 207 208sub regen_EXAMPLES { 209 my $perl = $^X; 210 if ($perl =~/\s/) { 211 $perl = qq{"$perl"}; 212 }; 213 (my $example_file = $main_file) =~ s!\.pm$!/Examples.pm!; 214 my $examples = `$perl -w examples/gen_examples_pod.pl`; 215 if ($examples) { 216 warn "(Re)Creating $example_file\n"; 217 $examples =~ s/\r\n/\n/g; 218 update_file( $example_file, $examples ); 219 }; 220}; 221 222sub update_file { 223 my( $filename, $new_content ) = @_; 224 my $content; 225 if( -f $filename ) { 226 open my $fh, '<', $filename 227 or die "Couldn't read '$filename': $!"; 228 binmode $fh; 229 local $/; 230 $content = <$fh>; 231 }; 232 233 if( $content ne $new_content ) { 234 if( open my $fh, '>', $filename ) { 235 binmode $fh; 236 print $fh $new_content; 237 } else { 238 warn "Couldn't (re)write '$filename': $!"; 239 }; 240 }; 241} 242