File: CreateCAPI.pm

package info (click to toggle)
libmath-int128-perl 0.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 604 kB
  • sloc: perl: 2,614; ansic: 340; makefile: 3
file content (59 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download
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
package inc::CreateCAPI;

use strict;
use warnings;
use autodie;

use Dist::Zilla::File::InMemory;

use Moose;

with 'Dist::Zilla::Role::FileGatherer',
    'Dist::Zilla::Role::FileInjector';

sub gather_files {
    my $self = shift;

    my @cmd = (
        'make_perl_module_c_api',
        'module_name=' . ( $self->zilla->name =~ s/-/::/gr ),
        'module_version=' . $self->zilla->version,
        q{author="} . ( join ', ', @{ $self->zilla->authors } ) . q{"},
    );

    $self->log( ["Running @cmd"] );

    system(@cmd) and die "Could not run @cmd";

    $self->_add_and_clean_file($_) for qw(
        c_api.h
        c_api_client/perl_math_int128.c
        c_api_client/perl_math_int128.h
        c_api_client/sample.xs
    );

    return;
}

sub _add_and_clean_file {
    my $self = shift;
    my $file = shift;

    open my $fh, '<', $file;
    my $content = do { local $/; <$fh> };
    close $fh;

    $self->add_file(
        Dist::Zilla::File::InMemory->new(
            name     => $file,
            content  => $content,
            added_by => [__PACKAGE__],
        )
    );

    unlink $file;

    return;
}

1;