Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 105 lines (80 sloc) 2.825 kb
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
package MyBuild;

use v5.10;
use base 'Module::Build';

# Override default 'code' action
# to allow compilation of perl5i.c
sub ACTION_code {
    my $self = shift;

    # This has to be run first so the PL files are run to generate
    # the C code for us to compile.
    $self->process_PL_files;

    if ( $self->is_windowsish ) {
        # Writing a C wrapper is too hard on Windows
        # Don't need it as there's no #! anyway
        # Just do a bat file
        $self->script_files("bin/perl5i.bat");
    }
    elsif ( $self->have_c_compiler() ) {
        my $b = $self->cbuilder();

        my $obj_file = $b->compile(
            source => 'bin/perl5i.c',
        );
        my $exe_file = $b->link_executable(objects => $obj_file);

        # script_files is set here as the resulting compiled
        # executable name varies based on operating system
        $self->script_files($exe_file);

        # Cleanup files from compilation
        $self->add_to_cleanup($obj_file, $exe_file);
    }
    else {
        # No C compiler, Unix style operating system.
        # Just use the Perl wrapper.
        File::Copy::copy("bin/perl5i.plx", "bin/perl5i");

        $self->script_files("bin/perl5i");
        $self->add_to_cleanup("bin/perl5i");
    }

    return $self->SUPER::ACTION_code;
}


# Run perltidy over all the Perl code
# Borrowed from Test::Harness
sub ACTION_tidy {
    my $self = shift;

    my %found_files = map { %$_ } $self->find_pm_files,
      $self->_find_file_by_type( 'pm', 't' ),
      $self->_find_file_by_type( 'pm', 'inc' ),
      $self->_find_file_by_type( 't', 't' ),
      $self->_find_file_by_type( 'PL', '.' );

    my @files = ( keys %found_files, map { $self->localize_file_path($_) } @extra );


    print "Running perltidy on @{[ scalar @files ]} files...\n";
    for my $file ( sort { $a cmp $b } @files ) {
        print " $file\n";
        system( 'perltidy', '-b', $file );
        unlink("$file.bak") if $? == 0;
    }
}

sub ACTION_critic {
    my $self = shift;

    my @files = keys %{ $self->find_pm_files };

    print "Running perlcritic on @{[ scalar @files ]} files...\n";
    system( "perlcritic", @files );
}

# Check if the built in local/gmtime work for a reasonable set of
# time. Some systems fail at 2**47 or beyond, and a lot fail at year
# 0, so those are good boundaries.
# This allows us to avoid depending on Time::y2038 which is a bit
# unreliable.
sub needs_y2038 {
    my $self = shift;

    state $limits = {
        # time year
        2**47-1 => 4461763,
        -62135510400 => 1,
    };

    for my $time (keys %$limits) {
        my $year = $limits->{$time};

        return 1 if (gmtime($time))[5] + 1900 != $year;
        return 1 if (localtime($time))[5] + 1900 != $year;
    }

    return 0;
}

1;
Something went wrong with that request. Please try again.