line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::cdif::Command; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1278
|
use v5.14; |
|
2
|
|
|
|
|
8
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
49
|
|
5
|
2
|
|
|
2
|
|
638
|
use utf8; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
13
|
|
6
|
2
|
|
|
2
|
|
52
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
7
|
2
|
|
|
2
|
|
16
|
use Fcntl; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
547
|
|
8
|
2
|
|
|
2
|
|
992
|
use IO::File; |
|
2
|
|
|
|
|
16867
|
|
|
2
|
|
|
|
|
290
|
|
9
|
2
|
|
|
2
|
|
15
|
use IO::Handle; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
10
|
2
|
|
|
2
|
|
12
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
462
|
use parent "App::cdif::Tmpfile"; |
|
2
|
|
|
|
|
295
|
|
|
2
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $debug; |
15
|
|
|
|
|
|
|
sub debug { |
16
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
17
|
0
|
0
|
|
|
|
|
if (@_) { |
18
|
0
|
|
|
|
|
|
$debug = shift; |
19
|
|
|
|
|
|
|
} else { |
20
|
0
|
|
|
|
|
|
$debug; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
25
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
26
|
0
|
|
|
|
|
|
my $obj = $class->SUPER::new; |
27
|
0
|
0
|
|
|
|
|
$obj->command(@_) if @_; |
28
|
0
|
|
|
|
|
|
$obj; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub command { |
32
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
33
|
0
|
0
|
|
|
|
|
if (@_) { |
34
|
0
|
|
|
|
|
|
$obj->{COMMAND} = [ @_ ]; |
35
|
0
|
|
|
|
|
|
$obj; |
36
|
|
|
|
|
|
|
} else { |
37
|
0
|
|
|
|
|
|
@{$obj->{COMMAND}}; |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub update { |
42
|
2
|
|
|
2
|
|
1264
|
use Time::localtime; |
|
2
|
|
|
|
|
9281
|
|
|
2
|
|
|
|
|
284
|
|
43
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
44
|
0
|
|
|
|
|
|
$obj->data(join "\n", map { $obj->execute($_) } $obj->command); |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$obj->date(ctime()); |
46
|
0
|
|
|
|
|
|
$obj; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub execute { |
50
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
51
|
0
|
|
|
|
|
|
my $command = shift; |
52
|
0
|
0
|
|
|
|
|
my @command = ref $command eq 'ARRAY' ? @$command : ($command); |
53
|
2
|
|
|
2
|
|
16
|
use IO::File; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1308
|
|
54
|
0
|
|
0
|
|
|
|
my $pid = (my $fh = IO::File->new)->open('-|') // die "open: $@\n"; |
55
|
0
|
0
|
|
|
|
|
if ($pid == 0) { |
56
|
0
|
0
|
|
|
|
|
if (my $stdin = $obj->{STDIN}) { |
57
|
0
|
0
|
|
|
|
|
open STDIN, "<&=", $stdin->fileno or die "open: $!\n"; |
58
|
0
|
|
|
|
|
|
binmode STDIN, ':encoding(utf8)'; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
open STDERR, ">&STDOUT"; |
61
|
0
|
|
|
|
|
|
exec @command; |
62
|
0
|
|
|
|
|
|
die "exec: $@\n"; |
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
|
binmode $fh, ':encoding(utf8)'; |
65
|
0
|
|
|
|
|
|
do { local $/; <$fh> }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub data { |
69
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
70
|
0
|
0
|
|
|
|
|
if (@_) { |
71
|
0
|
|
|
|
|
|
$obj->reset->write(shift)->flush->rewind; |
72
|
0
|
|
|
|
|
|
$obj; |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
|
$obj->rewind; |
75
|
0
|
|
|
|
|
|
my $data = do { local $/; $obj->fh->getline } ; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$obj->rewind; |
77
|
0
|
|
|
|
|
|
$data; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub date { |
82
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
83
|
0
|
0
|
|
|
|
|
@_ ? $obj->{DATE} = shift : $obj->{DATE}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub stdin { |
87
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
88
|
0
|
|
|
|
|
|
$obj->{STDIN}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub setstdin { |
92
|
0
|
|
|
0
|
0
|
|
my $obj = shift; |
93
|
0
|
|
|
|
|
|
my $data = shift; |
94
|
0
|
|
0
|
|
|
|
my $stdin = $obj->{STDIN} //= do { |
95
|
0
|
0
|
|
|
|
|
my $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n"; |
96
|
0
|
0
|
|
|
|
|
$fh->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n"; |
97
|
0
|
|
|
|
|
|
binmode $fh, ':encoding(utf8)'; |
98
|
0
|
|
|
|
|
|
$fh; |
99
|
|
|
|
|
|
|
}; |
100
|
0
|
0
|
|
|
|
|
$stdin->seek(0, 0) or die "seek: $!\n"; |
101
|
0
|
0
|
|
|
|
|
$stdin->truncate(0) or die "truncate: $!\n"; |
102
|
0
|
|
|
|
|
|
$stdin->print($data); |
103
|
0
|
0
|
|
|
|
|
$stdin->seek(0, 0) or die "seek: $!\n"; |
104
|
0
|
|
|
|
|
|
$obj; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |