Alien-CSFML

 view release on metacpan or  search on metacpan

inc/MBCSFML.pm  view on Meta::CPAN

package MBCSFML;
use strict;
use warnings;
use Exporter 5.57 'import';
our @EXPORT = qw/Build Build_PL/;
use CPAN::Meta;
use ExtUtils::Config 0.003;
use ExtUtils::Helpers 0.020
    qw/make_executable split_like_shell man1_pagename man3_pagename detildefy/;
use ExtUtils::Install qw/pm_to_blib install/;
use ExtUtils::InstallPaths 0.002;
use File::Basename        qw/basename dirname/;
use File::Find            ();
use File::Path            qw/mkpath/;
use File::Spec::Functions qw/catfile catdir rel2abs abs2rel splitdir/;
use Getopt::Long          qw/GetOptions/;
use JSON::Tiny            qw/encode_json decode_json/;
use File::pushd;
use File::Copy;
use File::Copy::Recursive qw[dircopy];
use Devel::CheckBin       qw[can_run];
use Env                   qw[@PATH];

sub write_file {
    my ( $filename, $mode, $content ) = @_;
    open my $fh, ">:$mode", $filename or die "Could not open $filename: $!\n";
    print $fh $content;
}

sub read_file {
    my ( $filename, $mode ) = @_;
    open my $fh, "<:$mode", $filename or die "Could not open $filename: $!\n";
    return do { local $/; <$fh> };
}

sub get_meta {
    my ($metafile) = grep { -e $_ } qw/META.json META.yml/ or die "No META information provided\n";
    return CPAN::Meta->load_file($metafile);
}

sub manify {
    my ( $input_file, $output_file, $section, $opts ) = @_;
    return if -e $output_file && -M $input_file <= -M $output_file;
    my $dirname = dirname($output_file);
    mkpath( $dirname, $opts->{verbose} ) if not -d $dirname;
    require Pod::Man;
    Pod::Man->new( section => $section )->parse_from_file( $input_file, $output_file );
    print "Manifying $output_file\n" if $opts->{verbose} && $opts->{verbose} > 0;
    return;
}

sub process_xs {
    my ( $source, $options ) = @_;
    die "Can't build xs files under --pureperl-only\n" if $options->{'pureperl-only'};
    my ( undef, @dirnames ) = splitdir( dirname($source) );
    my $file_base = basename( $source, '.xs' );
    my $archdir   = catdir( qw/blib arch auto/, @dirnames, $file_base );
    my $c_file    = catfile( 'lib', @dirnames, "$file_base.c" );
    require ExtUtils::ParseXS;
    ExtUtils::ParseXS::process_file( filename => $source, prototypes => 0, output => $c_file );
    my $version = $options->{meta}->version;
    require ExtUtils::CBuilder;
    my $builder = ExtUtils::CBuilder->new( config => $options->{config}->values_set );
    my $ob_file = $builder->compile(
        source  => $c_file,
        defines => { VERSION => qq/"$version"/, XS_VERSION => qq/"$version"/ }
    );
    mkpath( $archdir, $options->{verbose}, oct '755' ) unless -d $archdir;
    return $builder->link(
        objects     => $ob_file,
        lib_file    => catfile( $archdir, "$file_base." . $options->{config}->get('dlext') ),
        module_name => join '::',
        @dirnames, $file_base
    );
}

sub _mirror_extract {
    my ( $options, $url, $dest ) = @_;
    {
        require HTTP::Tiny;
        print "\nDownloading $url... ";
        my $out      = catdir( $dest, basename($url) );
        my $response = HTTP::Tiny->new->mirror( $url, $out );
        if ( $response->{success} ) {
            print " Done\n";
            print "Extracting $out... ";
            require Archive::Extract;
            my $ae = Archive::Extract->new( archive => $out );
            exit print " Fail! " . $ae->error if !$ae->extract();
            print "Done\n";
            return $ae->extract_path;
        }
        exit !!print " Fail!";
    }
}

sub build_libs {
    my ($options) = @_;
    my ( %libinfo, $dir );
    my $meta = $options->{meta};
    my $cwd  = rel2abs './';       # XXX - use Cwd;

    # This is an ugly cludge. A working, ugly cludge though. :\
    if ( !-d catdir( $cwd, 'share' ) ) {
        mkpath( catdir( $cwd, 'share' ), $options->{verbose}, oct '755' ) unless -d 'share';
        $dir = tempd();
        my $archdir = catdir( $cwd, qw[share] );



( run in 1.705 second using v1.01-cache-2.11-cpan-39bf76dae61 )