fix dist NAME, as per https://gist.github.com/miyagawa/5242916
[p5sagit/Distar.git] / bin / distar-init
CommitLineData
47b26c17 1#!/usr/bin/env perl
2
3use strict;
4use warnings FATAL => 'all';
5use File::Path qw(mkpath);
6
7my $project = $ARGV[0] or die "No project name passed";
8
9my @parts = split('-', $project);
10
11my $lib_file = join('/', 'lib', @parts).".pm";
12
13my $author = $ENV{DISTAR_INIT_AUTHOR} or die "DISTAR_INIT_AUTHOR unset";
14
15mkpath "${project}/maint";
16
17mkpath join('/', $project, 'lib', @parts[0..$#parts-1]);
18
5fb57e52 19my $package_name = join('::', @parts);
20
47b26c17 21open my $mpl_main, '>', "${project}/Makefile.PL"
22 or die "couldn't open Makefile.PL: $!";
23
5fb57e52 24print $mpl_main sprintf(<<'END', $package_name, $lib_file);
47b26c17 25use strict;
26use warnings FATAL => 'all';
27use ExtUtils::MakeMaker;
28
29(do 'maint/Makefile.PL.include' or die $@) unless -f 'META.yml';
30
31WriteMakefile(
32 NAME => '%s',
33 VERSION_FROM => '%s'
34);
35END
36
37close($mpl_main);
38
39open my $mpl_maint, '>', "${project}/maint/Makefile.PL.include"
40 or die "couldn't open maint/Makefile.PL.include: $!";
41
42print $mpl_maint sprintf(<<'END', $author);
43BEGIN {
44 -e 'Distar'
45 or system("git clone git://git.shadowcat.co.uk/p5sagit/Distar.git")
46}
47use lib 'Distar/lib';
48use Distar;
49
50author '%s';
51END
52
53close($mpl_maint);
54
55open my $pm, '>', "${project}/${lib_file}"
56 or die "Couldn't open .pm file: $!";
57
47b26c17 58my $year = 1900+(localtime)[5];
59
60my $mod_text = sprintf(<<'END', $package_name, $package_name, $author, $year, $package_name);
61 package %s;
62
63 our $VERSION = '0.000001'; # 0.0.1
64
65 $VERSION = eval $VERSION;
66
67 1;
68
69 =head1 NAME
70
71 %s - Description goes here
72
73 =head1 SYNOPSIS
74
75 =head1 DESCRIPTION
76
77 =head1 AUTHOR
78
79 %s
80
81 =head1 CONTRIBUTORS
82
83 None yet - maybe this software is perfect! (ahahahahahahahahaha)
84
85 =head1 COPYRIGHT
86
87 Copyright (c) %s the %s L</AUTHOR> and L</CONTRIBUTORS>
88 as listed above.
89
90 =head1 LICENSE
91
92 This library is free software and may be distributed under the same terms
93 as perl itself.
94END
95
96$mod_text =~ s/^ //mg;
97
98print $pm $mod_text;
99
100close $mod_text;
101
102chdir($project); system("git init");