File: Builder.pm

package info (click to toggle)
libdata-dump-streamer-perl 2.42-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 828 kB
  • sloc: perl: 3,206; makefile: 3
file content (125 lines) | stat: -rw-r--r-- 3,403 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package My::Builder;

use strict;
use warnings;

use Module::Build;
our @ISA= 'Module::Build';

sub new {
    my $class= shift @_;

    {
        my $B_Utils_required= 0.05;
        eval { require B::Utils; };
        if ($@ or B::Utils->VERSION < $B_Utils_required) {

            # If I don't have B::Utils then I must have ExtUtils::Depends
            my $ExtUtils_Depends_required=
                0.302;    #minimum version that works on Win32+gcc
            eval { require ExtUtils::Depends; };
            if ($@ or ExtUtils::Depends->VERSION < $ExtUtils_Depends_required) {
                print
                    "ExtUtils::Depends $ExtUtils_Depends_required is required to configure our B::Utils dependency, please install it manually or upgrade your CPAN/CPANPLUS\n";
                exit(0);
            }
        }
    }

    # Handle both: `./Build.PL DDS' and `./Build.PL NODDS'
    #
    my $create_dds_alias;
    if (@ARGV && $ARGV[0] =~ /^(?:NO)?DDS$/i) {
        my $arg= uc shift @ARGV;
        $create_dds_alias= 'DDS' eq $arg;
    }

    print "Installing Data::Dump::Streamer\n";

    if (!defined $create_dds_alias && -e '.answer' && open my $fh,
        "<", '.answer')
    {
        print
            "I will install (or not) the DDS shortcut as you requested previously.\n";
        print
            "If you wish to override the previous answer then state so explicitly\n";
        print "by saying 'perl Build.PL [NO]DDS'\n";
        my $cached_value= <$fh>;
        chomp $cached_value;
        print "Previous answer was: $cached_value\n";

        $create_dds_alias= 'yes' eq lc $cached_value;
    }

    if (!defined $create_dds_alias) {
        my $default= (
            0 == system(
                qq($^X -e "chdir '/';exit( eval { require DDS } ? 0: 1 )"))
                || (-e "./lib/DDS.pm"))
            ? 'yes'
            : 'no';
        print "\n";
        print "I can install a shortcut so you can use the package 'DDS'\n";
        print
            "as though it was 'Data::Dump::Streamer'. This is handy for oneliners.\n";
        print "*Note* that if you select 'no' below and you already\n";
        print "have it installed then it will be removed.\n";
        print "\n";
        my $yn=
            !!$class->y_n("Would you like me to install the shortcut? (yes/no)",
            $default);
        if (open my $fh, ">", '.answer') {
            print $fh $yn ? "yes\n" : "no\n";
            close $fh;
        }
        $create_dds_alias= $yn;
    }

    my $self= $class->SUPER::new(@_);

    if ($create_dds_alias) {
        print "I will also install DDS as an alias.\n";
        open my $ofh, ">", "./lib/DDS.pm"
            or die "Failed to open ./lib/DDS.pm: $!";
        print {$ofh} DDS();
        close $ofh;

        $self->add_to_cleanup('./lib/DDS.pm');
    }
    else {
        unlink "./lib/DDS.pm";
    }

    return $self;
}

sub DDS {
    my $text= <<'EOF_DDS';
##This all has to be one line for MakeMaker version scanning.
#use Data::Dump::Streamer (); BEGIN{ *DDS:: = \%Data::Dump::Streamer:: } $VERSION=$DDS::VERSION;
#1;
#
#=head1 NAME
#
#DDS - Alias for Data::Dump::Streamer
#
#=head1 SYNOPSIS
#
#  perl -MDDS -e "Dump \%INC"
#
#=head1 DESCRIPTION
#
#See L<Data::Dump::Streamer>.
#
#=head1 VERSION
#
# $Id: Makefile.PL 30 2006-04-16 15:33:25Z demerphq $
#
#=cut
#
EOF_DDS
    $text =~ s/^#//gm;
    return $text;
}

1;