replace strictures with strict+warnings
[p5sagit/Distar.git] / lib / Distar.pm
CommitLineData
42e08a83 1package Distar;
2
362ec4af 3use strict;
4use warnings FATAL => 'all';
42e08a83 5use base qw(Exporter);
ca3b3b8a 6use ExtUtils::MakeMaker ();
7use ExtUtils::MM ();
42e08a83 8
ca313d5a 9use Config;
28268771 10use File::Spec;
ca313d5a 11
37e295d8 12our $VERSION = '0.001000';
13$VERSION = eval $VERSION;
14
42e08a83 15our @EXPORT = qw(
5154970c 16 author manifest_include run_preflight
42e08a83 17);
18
19sub import {
20 strictures->import;
21 shift->export_to_level(1,@_);
22}
23
24sub author { our $Author = shift }
25
d7998bfa 26our $Ran_Preflight;
27
42e08a83 28our @Manifest = (
29 'lib' => '.pm',
30 't' => '.t',
31 't/lib' => '.pm',
32 'xt' => '.t',
33 'xt/lib' => '.pm',
1d950b4a 34 '' => qr{[^/]*\.PL},
42e08a83 35 '' => qr{Changes|MANIFEST|README|META\.yml},
42e08a83 36 'maint' => qr{[^.].*},
37);
38
39sub manifest_include {
40 push @Manifest, @_;
41}
42
43sub write_manifest_skip {
42e08a83 44 my @files = @Manifest;
45 my @parts;
46 while (my ($dir, $spec) = splice(@files, 0, 2)) {
47 my $re = ($dir ? $dir.'/' : '').
48 ((ref($spec) eq 'Regexp')
49 ? $spec
50 : !ref($spec)
51 ? ".*\Q${spec}\E"
a3e39afd 52 # print ref as well as stringification in case of overload ""
42e08a83 53 : die "spec must be string or regexp, was: ${spec} (${\ref $spec})");
54 push @parts, $re;
55 }
56 my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
19916679 57 open my $skip, '>', 'MANIFEST.SKIP'
58 or die "can't open MANIFEST.SKIP: $!";
42e08a83 59 print $skip "${final}\n";
60 close $skip;
61}
62
5154970c 63sub run_preflight {
d7998bfa 64 $Ran_Preflight = 1;
12b4d7c3 65 my $version = $ARGV[0];
d7998bfa 66
ca313d5a 67 my $make = $Config{make};
28268771 68 my $null = File::Spec->devnull;
ca313d5a 69
a973b068 70 system("git fetch");
71 if (system("git rev-parse --quiet --verify v$version >$null") == 0) {
72 die "Tag v$version already exists!";
73 }
74
12b4d7c3 75 require File::Find;
76 File::Find::find({ no_chdir => 1, wanted => sub {
77 return
78 unless -f && /\.pm$/;
79 my $file_version = MM->parse_version($_);
80 die "Module $_ version $file_version doesn't match dist version $version"
81 unless $file_version eq 'undef' || $file_version eq $version;
82 }}, 'lib');
83
4df609ef 84 for (scalar `"$make" manifest 2>&1 >$null`) {
ca313d5a 85 $_ && die "$make manifest changed:\n$_ Go check it and retry";
41c39fda 86 }
87
5154970c 88 for (scalar `git status`) {
50d3c4ad 89 /^# On branch master/ || die "Not on master. EEEK";
325f6231 90 /Your branch is behind|Your branch and .*? have diverged/ && die "Not synced with upstream";
5154970c 91 }
92
93 for (scalar `git diff`) {
7374f43f 94 length && die "Outstanding changes";
5154970c 95 }
5154970c 96 my $ymd = sprintf(
97 "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3]
98 );
0887b8ff 99 my $changes_line = "$version - $ymd\n";
59fcfa65 100 my @cached = grep /^\+/, `git diff --cached -U0`;
e2d04df8 101 @cached > 0 or die "Please add:\n\n$changes_line\nto Changes stage Changes (git add Changes)";
59fcfa65 102 @cached == 2 or die "Pre-commit Changes not just Changes line";
c373c51b 103 $cached[0] =~ /^\+\+\+ .\/Changes\n/ or die "Changes not changed";
e2d04df8 104 $cached[1] eq "+$changes_line" or die "Changes new line should be: \n\n$changes_line ";
5154970c 105}
106
ca3b3b8a 107{
108 package Distar::MM;
109 our @ISA = @ExtUtils::MM::ISA;
110 @ExtUtils::MM::ISA = (__PACKAGE__);
111
112 sub new {
113 my ($class, $args) = @_;
114 return $class->SUPER::new({
115 LICENSE => 'perl',
116 %$args,
117 AUTHOR => $Distar::Author,
118 ABSTRACT_FROM => $args->{VERSION_FROM},
119 test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t' },
120 });
121 }
122
123 sub dist_test {
124 my $self = shift;
125 my $dist_test = $self->SUPER::dist_test(@_) . <<'END';
b0401762 126
ca3b3b8a 127# --- Distar section:
5154970c 128preflight:
584b890c 129 perl -IDistar/lib -MDistar -erun_preflight $(VERSION)
72932296 130release: preflight
131 $(MAKE) disttest
27dbd26e 132 rm -rf $(DISTVNAME)
133 $(MAKE) $(DISTVNAME).tar$(SUFFIX)
42e08a83 134 git commit -a -m "Release commit for $(VERSION)"
401ece0b 135 git tag v$(VERSION) -m "release v$(VERSION)"
65a1f7d9 136 cpan-upload $(DISTVNAME).tar$(SUFFIX)
2c636792 137 git push origin v$(VERSION) HEAD
5154970c 138distdir: readmefile
139readmefile: create_distdir
140 pod2text $(VERSION_FROM) >$(DISTVNAME)/README
046ee554 141 $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-readme-to-manifest
ca3b3b8a 142
42e08a83 143END
a2f6bc7b 144 if (open my $fh, '<', 'maint/Makefile.include') {
ca3b3b8a 145 $dist_test .= do { local $/; <$fh> };
a2f6bc7b 146 }
ca3b3b8a 147 return $dist_test;
42e08a83 148 }
149}
150
151END {
d7998bfa 152 write_manifest_skip() unless $Ran_Preflight
42e08a83 153}
154
1551;