7169783e63508e308382fe8ed867ffcd544b076f
[p5sagit/Distar.git] / lib / Distar.pm
1 package Distar;
2
3 use strictures 1;
4 use base qw(Exporter);
5
6 our @EXPORT = qw(
7   author manifest_include
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},
25   '' => qr{t/smells-of-vcs/.svn},
26   'maint' => qr{[^.].*},
27 );
28
29 sub manifest_include {
30   push @Manifest, @_;
31 }
32
33 sub write_manifest_skip {
34   use autodie;
35   my @files = @Manifest;
36   my @parts;
37   while (my ($dir, $spec) = splice(@files, 0, 2)) {
38     my $re = ($dir ? $dir.'/' : '').
39       ((ref($spec) eq 'Regexp')
40         ? $spec
41         : !ref($spec)
42           ? ".*\Q${spec}\E"
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
52 sub MY::postamble { <<'END'; }
53 upload: $(DISTVNAME).tar$(SUFFIX)
54         cpan-upload $<
55 release: upload
56         git commit -a -m "Release commit for $(VERSION)"
57         git tag release_$(VERSION)
58         git push
59         git push --tags
60 END
61
62 {
63   no warnings 'redefine';
64   sub main::WriteMakefile {
65     my %args = @_;
66     system("pod2text $args{VERSION_FROM} >README");
67     ExtUtils::MakeMaker::WriteMakefile(
68       @_, AUTHOR => our $Author, ABSTRACT_FROM => $args{VERSION_FROM},
69       test => { TESTS => ($args{test}{TESTS}||'').' xt/*.t' },
70     );
71   }
72 }
73
74 END {
75   write_manifest_skip()
76 }
77
78 1;