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