summaryrefslogtreecommitdiff
path: root/Makefile.PL
blob: 887584677538f6b3370b00008efd59abc3279c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use inc::Module::Install;
name 'carton';
version_from 'lib/Carton.pm';
perl_version '5.008001';
license_from 'lib/Carton.pod';
readme_from('lib/Carton.pod');

configure_requires 'version', 0.77;

requires 'JSON', 2.53;
requires 'App::cpanminus', 1.4900;
requires 'Term::ANSIColor', 1.12;
requires 'Module::Metadata', 1.000003;
requires 'Try::Tiny', 0.09;
requires 'parent', 0.223;
requires 'Config::GitLike', 1.05;

install_script 'bin/carton';

doc_to_pods();

build_requires 'Test::More', 0.88;
test_requires 'Test::Requires';
auto_set_repository();

resources
    homepage => 'https://github.com/miyagawa/carton',
    bugtracker => 'https://github.com/miyagawa/carton/issues';

WriteAll;

sub doc_to_pods {
    # lib/Carton/Doc/*.pod => docs/carton-*.pod => blib/man1/carton-*.1

    my %pods;

    for my $file ("lib/Carton.pod", glob "lib/Carton/Doc/*.pod") {
        my $base = ($file =~ m!lib/(.*?)\.pod!)[0];
           $base =~ s!/!::!g;
        my $name = $base eq 'Carton' ? "carton" : ("carton-" . lc( (split /::/, $base)[-1] ));
        my $doc = "docs/$name.pod";

        if ($Module::Install::AUTHOR) {
            mkdir "docs", 0777;
            copy_pod($file, $doc, $base => $name);
        }

        $pods{$doc} = "blib/man1/$name.1"
    }

    \%pods;

    makemaker_args MAN1PODS => \%pods;
}

sub copy_pod {
    my($src, $dest, $pod_name, $man) = @_;

    warn "Copying $src -> $dest\n";

    open my $in, "<", $src    or die "$src: $!";
    open my $out, ">", $dest  or die "$dest: $!";

    my $match;
    while (<$in>) {
        unless ($match) {
            s/^$pod_name - /$man - /
                and $match++;
        }
        print $out $_;
    }

    unless ($match) {
        die "Couldn't find NAME $pod_name in $src";
    }
}