remove unneeded use lines
[p5sagit/Distar.git] / lib / Distar.pm
1 package Distar;
2
3 use strict;
4 use warnings FATAL => 'all';
5 use base qw(Exporter);
6 use ExtUtils::MakeMaker ();
7 use ExtUtils::MM ();
8
9 our $VERSION = '0.002000';
10 $VERSION = eval $VERSION;
11
12 my $MM_VER = eval $ExtUtils::MakeMaker::VERSION;
13
14 our @EXPORT = qw(
15   author manifest_include readme_generator
16 );
17
18 sub import {
19   strict->import;
20   warnings->import(FATAL => 'all');
21   shift->export_to_level(1,@_);
22 }
23
24 sub author {
25   our $Author = shift;
26   $Author = [ $Author ]
27     if !ref $Author;
28 }
29
30 our @Manifest = (
31   'lib' => '.pm',
32   'lib' => '.pod',
33   't' => '.t',
34   't/lib' => '.pm',
35   'xt' => '.t',
36   'xt/lib' => '.pm',
37   '' => qr{[^/]*\.PL},
38   '' => qr{Changes|MANIFEST|README|LICENSE|META\.yml},
39   'maint' => qr{[^.].*},
40 );
41
42 sub manifest_include {
43   push @Manifest, @_;
44 }
45
46 sub readme_generator {
47   die "readme_generator unsupported" if @_ && $_[0];
48 }
49
50 sub write_manifest_skip {
51   my @files = @Manifest;
52   my @parts;
53   while (my ($dir, $spec) = splice(@files, 0, 2)) {
54     my $re = ($dir ? $dir.'/' : '').
55       ((ref($spec) eq 'Regexp')
56         ? $spec
57         : !ref($spec)
58           ? ".*\Q${spec}\E"
59             # print ref as well as stringification in case of overload ""
60           : die "spec must be string or regexp, was: ${spec} (${\ref $spec})");
61     push @parts, $re;
62   }
63   my $final = '^(?!'.join('|', map "${_}\$", @parts).')';
64   open my $skip, '>', 'MANIFEST.SKIP'
65     or die "can't open MANIFEST.SKIP: $!";
66   print $skip "${final}\n";
67   close $skip;
68 }
69
70 {
71   package Distar::MM;
72   our @ISA = @MM::ISA;
73   @MM::ISA = (__PACKAGE__);
74
75   sub new {
76     my ($class, $args) = @_;
77     return $class->SUPER::new({
78       LICENSE => 'perl_5',
79       MIN_PERL_VERSION => '5.006',
80       AUTHOR => ($MM_VER >= 6.5702 ? $Distar::Author : join(', ', @$Distar::Author)),
81       %$args,
82       ABSTRACT_FROM => $args->{VERSION_FROM},
83       test => { TESTS => ($args->{test}{TESTS}||'t/*.t').' xt/*.t xt/*/*.t' },
84       realclean => { FILES => (
85         ($args->{realclean}{FILES}||'')
86         . ' Distar/ MANIFEST.SKIP MANIFEST MANIFEST.bak'
87       ) },
88     });
89   }
90
91   sub flush {
92     my $self = shift;
93     Distar::write_manifest_skip();
94     $self->SUPER::flush(@_);
95   }
96
97   sub dist_test {
98     my $self = shift;
99     my $dist_test = $self->SUPER::dist_test(@_);
100
101     $dist_test .= <<"END";
102
103 # --- Distar section:
104
105 REMAKE = \$(PERLRUN) Makefile.PL @{[ map { $self->quote_literal($_) } @ARGV ]}
106
107 END
108     $dist_test .= <<'END';
109 preflight:
110         $(ABSPERLRUN) Distar/helpers/preflight $(VERSION)
111 release: preflight
112         $(MAKE) disttest
113         $(RM_RF) $(DISTVNAME)
114         $(MAKE) $(DISTVNAME).tar$(SUFFIX)
115         git commit -a -m "Release commit for $(VERSION)"
116         git tag v$(VERSION) -m "release v$(VERSION)"
117         cpan-upload $(DISTVNAME).tar$(SUFFIX)
118         git push origin v$(VERSION) HEAD
119 distdir: readmefile
120 readmefile: create_distdir $(DISTVNAME)/README
121         $(NOECHO) cd $(DISTVNAME) && $(ABSPERLRUN) ../Distar/helpers/add-to-manifest README
122 $(DISTVNAME)/README: $(VERSION_FROM)
123         $(NOECHO) $(MKPATH) $(DISTVNAME)
124         pod2text $(VERSION_FROM) >$(DISTVNAME)/README
125 disttest: distmanicheck
126 distmanicheck: create_distdir
127         cd $(DISTVNAME) && $(ABSPERLRUN) "-MExtUtils::Manifest=manicheck" -e "exit manicheck"
128 nextrelease:
129         $(ABSPERLRUN) Distar/helpers/add-changelog-heading $(VERSION) Changes
130         git add -p Changes
131 refresh:
132         cd Distar && git pull
133         rm Makefile
134         $(REMAKE)
135 END
136
137     my $include = '';
138     if (open my $fh, '<', 'maint/Makefile.include') {
139       $include = "\n# --- Makefile.include:\n" . do { local $/; <$fh> };
140     }
141
142     for my $type ('', 'minor', 'major') {
143       if ($include !~ /^bump$type:/m) {
144         my $arg = $type || '$(V)';
145         $dist_test .= <<"END"
146 bump$type:
147         \$(ABSPERLRUN) Distar/helpers/bump-version --git \$(VERSION) $arg
148         \$(RM_F) \$(FIRST_MAKEFILE)
149         \$(REMAKE)
150 END
151       }
152     }
153
154     $dist_test .= $include . "\n";
155
156     return $dist_test;
157   }
158 }
159
160 1;