App-Greple-update

 view release on metacpan or  search on metacpan

lib/App/Greple/update.pm  view on Meta::CPAN

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
my $fh;
state $fdpath = do {
    my $fd = DATA->fileno;
    first { -r "$_/$fd" } qw( /dev/fd /proc/self/fd );
};
 
if ($fdpath and $remember_data) {
    use IO::File;
    use Fcntl;
    $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n";
    $fh->binmode(':encoding(utf8)');
    my $fd = $fh->fcntl(F_GETFD, 0) or die "fcntl F_GETFD: $!\n";
    $fh->fcntl(F_SETFD, $fd & ~FD_CLOEXEC) or die "fcntl F_SETFD: $!\n";
    $fh->printflush($contents);
    $fh->seek(0, 0);
    $orig = sprintf "%s/%d", $fdpath, $fh->fileno;
}
 
@update_diffcmd or confess "Empty diff command";
exec @update_diffcmd, $orig, "-";
die "exec: $!\n";

t/runner/Runner.pm  view on Meta::CPAN

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
 
sub run {
    my $obj = shift;
    use IO::File;
    my $pid = (my $fh = new IO::File)->open('-|') // die "open: $@\n";
    if ($pid == 0) {
        if (my $stdin = $obj->{STDIN}) {
            open STDIN, "<&=", $stdin->fileno or die "open: $!\n";
            $stdin->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n";
            binmode STDIN, ':encoding(utf8)';
        }
        open STDERR, ">&STDOUT";
        $obj->execute;
        exit 1;
    }
    $obj->{STDIN} = undef;
    binmode $fh, ':encoding(utf8)';
    $obj->{stdout} = do { local $/; <$fh> };
    my $child = wait;
    $child != $pid and die "child = $child, pid = $pid";
    $obj->{pid} = $pid;
    $obj->{result} = $?;
    $obj;
}
 
sub status {
    my $obj = shift;

t/runner/Runner.pm  view on Meta::CPAN

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
}
 
*result = \&stdout; # for backward compatibility
 
sub setstdin {
    my $obj = shift;
    my $data = shift;
    my $stdin = $obj->{STDIN} //= do {
        my $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n";
        $fh->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n";
        binmode $fh, ':encoding(utf8)';
        $fh;
    };
    $stdin->seek(0, 0)  or die "seek: $!\n";
    $stdin->truncate(0) or die "truncate: $!\n";
    $stdin->print($data);
    $stdin->seek(0, 0)  or die "seek: $!\n";
    $obj;
}
 
##



( run in 0.339 second using v1.01-cache-2.11-cpan-bf8d7bb2d05 )