Commit | Line | Data |
42e08a83 |
1 | package Distar; |
2 | |
3 | use strictures 1; |
4 | use base qw(Exporter); |
5 | |
6 | our @EXPORT = qw( |
5154970c |
7 | author manifest_include run_preflight |
42e08a83 |
8 | ); |
9 | |
10 | sub import { |
11 | strictures->import; |
12 | shift->export_to_level(1,@_); |
13 | } |
14 | |
15 | sub author { our $Author = shift } |
16 | |
17 | our @Manifest = ( |
18 | 'lib' => '.pm', |
19 | 't' => '.t', |
20 | 't/lib' => '.pm', |
21 | 'xt' => '.t', |
22 | 'xt/lib' => '.pm', |
23 | '' => '.PL', |
24 | '' => qr{Changes|MANIFEST|README|META\.yml}, |
42e08a83 |
25 | 'maint' => qr{[^.].*}, |
26 | ); |
27 | |
28 | sub manifest_include { |
29 | push @Manifest, @_; |
30 | } |
31 | |
32 | sub write_manifest_skip { |
33 | use autodie; |
34 | my @files = @Manifest; |
35 | my @parts; |
36 | while (my ($dir, $spec) = splice(@files, 0, 2)) { |
37 | my $re = ($dir ? $dir.'/' : ''). |
38 | ((ref($spec) eq 'Regexp') |
39 | ? $spec |
40 | : !ref($spec) |
41 | ? ".*\Q${spec}\E" |
a3e39afd |
42 | # print ref as well as stringification in case of overload "" |
42e08a83 |
43 | : die "spec must be string or regexp, was: ${spec} (${\ref $spec})"); |
44 | push @parts, $re; |
45 | } |
46 | my $final = '^(?!'.join('|', map "${_}\$", @parts).')'; |
47 | open my $skip, '>', 'MANIFEST.SKIP'; |
48 | print $skip "${final}\n"; |
49 | close $skip; |
50 | } |
51 | |
5154970c |
52 | sub run_preflight { |
53 | system("git fetch"); |
54 | |
55 | for (scalar `git status`) { |
56 | /Your branch is (behind|ahead of)/ && die "Not synced with upstream"; |
57 | } |
58 | |
59 | for (scalar `git diff`) { |
60 | length && die "Oustanding changes"; |
61 | } |
5154970c |
62 | my $ymd = sprintf( |
63 | "%i-%02i-%02i", (localtime)[5]+1900, (localtime)[4]+1, (localtime)[3] |
64 | ); |
59fcfa65 |
65 | my @cached = grep /^\+/, `git diff --cached -U0`; |
66 | @cached > 0 or die "Please add:\n\n$ARGV[0] - $ymd\n\nto Changes and git add"; |
67 | @cached == 2 or die "Pre-commit Changes not just Changes line"; |
68 | $cached[0] eq "+++ b/Changes\n" or die "Changes not changed"; |
5154970c |
69 | $cached[1] eq "+$ARGV[0] - $ymd\n" or die "Changes new line should be: \n\n$ARGV[0] - $ymd\n "; |
70 | } |
71 | |
42e08a83 |
72 | sub MY::postamble { <<'END'; } |
5154970c |
73 | preflight: |
74 | perl -Idistar/lib -MDistar -erun_preflight $(VERSION) |
e06cbac3 |
75 | upload: preflight $(DISTVNAME).tar$(SUFFIX) |
5154970c |
76 | cpan-upload $(DISTVNAME).tar$(SUFFIX) |
42e08a83 |
77 | release: upload |
78 | git commit -a -m "Release commit for $(VERSION)" |
79 | git tag release_$(VERSION) |
80 | git push |
81 | git push --tags |
5154970c |
82 | distdir: readmefile |
83 | readmefile: create_distdir |
84 | pod2text $(VERSION_FROM) >$(DISTVNAME)/README |
59fcfa65 |
85 | $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) -MExtUtils::Manifest=maniadd -e 'eval { maniadd({q{README} => q{README file (added by Distar)}}) } ' \ |
86 | -e ' or print "Could not add README to MANIFEST: $${'\''@'\''}\n"' -- |
42e08a83 |
87 | END |
88 | |
89 | { |
90 | no warnings 'redefine'; |
91 | sub main::WriteMakefile { |
92 | my %args = @_; |
42e08a83 |
93 | ExtUtils::MakeMaker::WriteMakefile( |
2f88acd6 |
94 | LICENSE => 'perl', |
42e08a83 |
95 | @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM}, |
96 | test => { TESTS => ($args{test}{TESTS}||'').' xt/*.t' }, |
97 | ); |
98 | } |
99 | } |
100 | |
101 | END { |
102 | write_manifest_skip() |
103 | } |
104 | |
105 | 1; |