line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fauxtobox; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
65782
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Exporter; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
836
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
2
|
|
|
2
|
|
26
|
my $class = shift; |
13
|
2
|
0
|
|
|
|
8
|
@_ = map /^[a-z0-9]+\z/ ? '$_' . $_ : $_, @_; |
14
|
2
|
|
|
|
|
7
|
unshift @_, $class; |
15
|
2
|
|
|
|
|
3
|
goto &{ $class->can('SUPER::import') }; |
|
2
|
|
|
|
|
8564
|
|
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub eval_string { |
19
|
82
|
|
|
82
|
0
|
97
|
my ($code) = @_; |
20
|
82
|
|
|
|
|
8796
|
my $v = eval $code; |
21
|
82
|
50
|
|
|
|
705
|
die $@ if $@; |
22
|
82
|
|
|
|
|
368
|
$v |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _filetest { |
26
|
54
|
|
|
54
|
|
89
|
my ($name) = @_; |
27
|
54
|
|
|
|
|
145
|
"test_$name" => eval_string("sub { -$name \$_[0] }") |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _xlist { |
31
|
16
|
|
|
16
|
|
28
|
my ($n, $name) = @_; |
32
|
16
|
|
|
|
|
100
|
my $xs = join '', map "\$x$_, ", 1 .. $n; |
33
|
16
|
|
|
|
|
64
|
$name => eval_string "sub { my (\$arg, $xs) = \@_; $name(${xs}ref(\$arg) eq 'ARRAY' ? \@\$arg : \$_[0]) }" |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _fixed_opt { |
37
|
122
|
|
|
122
|
|
158
|
my ($n, $m, $name) = @_; |
38
|
|
|
|
|
|
|
$name => do { |
39
|
2
|
|
|
2
|
|
12
|
no warnings 'once'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
90
|
|
40
|
2
|
|
|
2
|
|
10
|
no strict 'refs'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
6718
|
|
41
|
|
|
|
|
|
|
*{"CORE::$name"}{CODE} |
42
|
122
|
|
66
|
|
|
513
|
} || eval_string do { |
43
|
|
|
|
|
|
|
my $args = join ', ', map "\$_[$_]", 0 .. $n - 1; |
44
|
|
|
|
|
|
|
my $base = "$name $args"; |
45
|
|
|
|
|
|
|
my $code = $base; |
46
|
|
|
|
|
|
|
for my $c (0 .. $m - 1) { |
47
|
|
|
|
|
|
|
my $i = $n + $c; |
48
|
|
|
|
|
|
|
$base .= ", \$_[$i]"; |
49
|
|
|
|
|
|
|
$code = "\@_ > $i ? $base : $code"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
"sub { $code }" |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _fixed { |
56
|
116
|
|
|
116
|
|
605
|
my ($n, $name) = @_; |
57
|
116
|
|
|
|
|
217
|
_fixed_opt $n, 0, $name |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _scalar { |
61
|
94
|
|
|
94
|
|
157
|
my ($name) = @_; |
62
|
94
|
|
|
|
|
154
|
_fixed 1, $name |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _hxa { |
66
|
6
|
|
|
6
|
|
13
|
my ($name) = @_; |
67
|
6
|
50
|
|
|
|
98
|
my $body = |
68
|
|
|
|
|
|
|
$^V ge v5.12.0 ? |
69
|
|
|
|
|
|
|
"ref(\$_[0]) eq 'ARRAY' ? $name \@{\$_[0]} : $name %{\$_[0]}" : |
70
|
|
|
|
|
|
|
"$name %{\$_[0]}" |
71
|
|
|
|
|
|
|
; |
72
|
6
|
100
|
|
|
|
40
|
$body = "[$body]" unless $name eq 'each'; |
73
|
6
|
|
|
|
|
23
|
$name => eval_string("sub { $body }") |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my %functions = ( |
77
|
|
|
|
|
|
|
apply => sub { my $x = shift; my $f = shift; $f->($x, @_) }, |
78
|
|
|
|
|
|
|
list => sub { ref($_[0]) eq 'HASH' ? %{$_[0]} : @{$_[0]} }, |
79
|
|
|
|
|
|
|
qr => sub { @_ > 1 ? qr/(?$_[1])$_[0]/ : qr/$_[0]/ }, |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
m => sub { $_[0] =~ /$_[1]/ }, |
82
|
|
|
|
|
|
|
m_g => sub { $_[0] =~ /$_[1]/g }, |
83
|
|
|
|
|
|
|
m_gc => sub { $_[0] =~ /$_[1]/gc }, |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
s => sub { ref($_[2]) ? $_[0] =~ s/$_[1]/$_[2]()/e : $_[0] =~ s/$_[1]/$_[2]/ }, |
86
|
|
|
|
|
|
|
s_g => sub { ref($_[2]) ? $_[0] =~ s/$_[1]/$_[2]()/ge : $_[0] =~ s/$_[1]/$_[2]/g }, |
87
|
|
|
|
|
|
|
$^V ge v5.14.0 ? ( |
88
|
|
|
|
|
|
|
s_r => eval_string('sub { ref($_[2]) ? $_[0] =~ s/$_[1]/$_[2]()/re : $_[0] =~ s/$_[1]/$_[2]/r }'), |
89
|
|
|
|
|
|
|
s_gr => eval_string('sub { ref($_[2]) ? $_[0] =~ s/$_[1]/$_[2]()/gre : $_[0] =~ s/$_[1]/$_[2]/gr }'), |
90
|
|
|
|
|
|
|
) : ( |
91
|
|
|
|
|
|
|
s_r => sub { my $s = $_[0]; if (ref $_[2]) { $s =~ s/$_[1]/$_[2]()/e } else { $s =~ s/$_[1]/$_[2]/ } $s }, |
92
|
|
|
|
|
|
|
s_gr => sub { my $s = $_[0]; if (ref $_[2]) { $s =~ s/$_[1]/$_[2]()/ge } else { $s =~ s/$_[1]/$_[2]/g } $s }, |
93
|
|
|
|
|
|
|
), |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
(map _filetest($_), qw( |
96
|
|
|
|
|
|
|
r w x o |
97
|
|
|
|
|
|
|
R W X O |
98
|
|
|
|
|
|
|
e z s |
99
|
|
|
|
|
|
|
f d l p S b c t |
100
|
|
|
|
|
|
|
u g k |
101
|
|
|
|
|
|
|
T B |
102
|
|
|
|
|
|
|
M A C |
103
|
|
|
|
|
|
|
)), |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
_scalar('abs'), |
106
|
|
|
|
|
|
|
_scalar('alarm'), |
107
|
|
|
|
|
|
|
_fixed(2, 'atan2'), |
108
|
|
|
|
|
|
|
bless => defined &CORE::bless ? \&CORE::bless : sub { bless $_[0], @_ > 1 ? $_[1] : scalar caller }, |
109
|
|
|
|
|
|
|
_scalar('chdir'), |
110
|
|
|
|
|
|
|
_xlist(1, 'chmod'), |
111
|
|
|
|
|
|
|
_xlist(0, 'chomp'), |
112
|
|
|
|
|
|
|
_xlist(0, 'chop'), |
113
|
|
|
|
|
|
|
_xlist(2, 'chown'), |
114
|
|
|
|
|
|
|
_scalar('chr'), |
115
|
|
|
|
|
|
|
_scalar('chroot'), |
116
|
|
|
|
|
|
|
_scalar('cos'), |
117
|
|
|
|
|
|
|
_fixed(2, 'crypt'), |
118
|
|
|
|
|
|
|
defined => sub { defined $_[0] }, |
119
|
|
|
|
|
|
|
delete => sub { |
120
|
|
|
|
|
|
|
ref($_[0]) eq 'ARRAY' ? |
121
|
|
|
|
|
|
|
delete $_[0][$_[1]] : |
122
|
|
|
|
|
|
|
delete $_[0]{$_[1]} |
123
|
|
|
|
|
|
|
}, |
124
|
|
|
|
|
|
|
_scalar('die'), |
125
|
|
|
|
|
|
|
_hxa('each'), |
126
|
|
|
|
|
|
|
eval => sub { eval $_[0] }, |
127
|
|
|
|
|
|
|
exec => sub { |
128
|
|
|
|
|
|
|
my $prog = shift; |
129
|
|
|
|
|
|
|
@_ ? exec { $prog } @_ : |
130
|
|
|
|
|
|
|
ref($prog) eq 'ARRAY' ? exec @$prog : |
131
|
|
|
|
|
|
|
exec $prog |
132
|
|
|
|
|
|
|
}, |
133
|
|
|
|
|
|
|
exists => sub { |
134
|
|
|
|
|
|
|
ref($_[0]) eq 'ARRAY' ? |
135
|
|
|
|
|
|
|
exists $_[0][$_[1]] : |
136
|
|
|
|
|
|
|
exists $_[0]{$_[1]} |
137
|
|
|
|
|
|
|
}, |
138
|
|
|
|
|
|
|
_scalar('exit'), |
139
|
|
|
|
|
|
|
_scalar('exp'), |
140
|
|
|
|
|
|
|
$^V ge v5.16.0 ? (fc => \&CORE::fc) : (), |
141
|
|
|
|
|
|
|
_scalar('getpgrp'), |
142
|
|
|
|
|
|
|
_scalar('getpwnam'), |
143
|
|
|
|
|
|
|
_scalar('getgrnam'), |
144
|
|
|
|
|
|
|
_scalar('gethostbyname'), |
145
|
|
|
|
|
|
|
_scalar('getnetbyname'), |
146
|
|
|
|
|
|
|
_scalar('getprotobyname'), |
147
|
|
|
|
|
|
|
_scalar('getpwuid'), |
148
|
|
|
|
|
|
|
_scalar('getgrgid'), |
149
|
|
|
|
|
|
|
_fixed(2, 'getservbyname'), |
150
|
|
|
|
|
|
|
_fixed(2, 'gethostbyaddr'), |
151
|
|
|
|
|
|
|
_fixed(2, 'getnetbyaddr'), |
152
|
|
|
|
|
|
|
_scalar('getprotobynumber'), |
153
|
|
|
|
|
|
|
_fixed(2, 'getservbyport'), |
154
|
|
|
|
|
|
|
glob => sub { [ glob $_[0] ] }, |
155
|
|
|
|
|
|
|
_scalar('gmtime'), |
156
|
|
|
|
|
|
|
grep => sub { my ($arg, $f) = @_; [ grep $f->($_), @$arg ] }, |
157
|
|
|
|
|
|
|
_scalar('hex'), |
158
|
|
|
|
|
|
|
_fixed_opt(2, 1, 'index'), |
159
|
|
|
|
|
|
|
_scalar('int'), |
160
|
|
|
|
|
|
|
join => sub { join $_[1], @{$_[0]} }, |
161
|
|
|
|
|
|
|
_hxa('keys'), |
162
|
|
|
|
|
|
|
_xlist(1, 'kill'), |
163
|
|
|
|
|
|
|
_scalar('lc'), |
164
|
|
|
|
|
|
|
_scalar('lcfirst'), |
165
|
|
|
|
|
|
|
_scalar('length'), |
166
|
|
|
|
|
|
|
_fixed(2, 'link'), |
167
|
|
|
|
|
|
|
_scalar('localtime'), |
168
|
|
|
|
|
|
|
_scalar('log'), |
169
|
|
|
|
|
|
|
_scalar('lstat'), |
170
|
|
|
|
|
|
|
map => sub { my ($arg, $f) = @_; [ map $f->($_), @$arg ] }, |
171
|
|
|
|
|
|
|
_scalar('mkdir'), |
172
|
|
|
|
|
|
|
_scalar('oct'), |
173
|
|
|
|
|
|
|
_scalar('ord'), |
174
|
|
|
|
|
|
|
_xlist(1, 'pack'), |
175
|
|
|
|
|
|
|
pop => sub { pop @{$_[0]} }, |
176
|
|
|
|
|
|
|
pos => sub :lvalue { @_ > 1 ? pos($_[0]) = $_[1] : pos($_[0]) }, |
177
|
|
|
|
|
|
|
_scalar('prototype'), |
178
|
|
|
|
|
|
|
push => sub { my $arg = shift; push @$arg, @_ }, |
179
|
|
|
|
|
|
|
_scalar('quotemeta'), |
180
|
|
|
|
|
|
|
_scalar('rand'), |
181
|
|
|
|
|
|
|
_scalar('readlink'), |
182
|
|
|
|
|
|
|
_scalar('ref'), |
183
|
|
|
|
|
|
|
_fixed(2, 'rename'), |
184
|
|
|
|
|
|
|
_scalar('require'), |
185
|
|
|
|
|
|
|
reverse => sub { ref($_[0]) eq 'ARRAY' ? [ reverse @{$_[0]} ] : scalar reverse $_[0] }, |
186
|
|
|
|
|
|
|
_fixed_opt(2, 1, 'rindex'), |
187
|
|
|
|
|
|
|
_scalar('rmdir'), |
188
|
|
|
|
|
|
|
shift => sub { shift @{$_[0]} }, |
189
|
|
|
|
|
|
|
_scalar('sin'), |
190
|
|
|
|
|
|
|
_scalar('sleep'), |
191
|
|
|
|
|
|
|
sort => sub { [ @_ > 1 ? sort { $_[1]($a, $b) } @{$_[0]} : sort @{$_[0]} ] }, |
192
|
|
|
|
|
|
|
splice => sub { |
193
|
|
|
|
|
|
|
my $arg = shift; |
194
|
|
|
|
|
|
|
return splice @$arg unless @_; |
195
|
|
|
|
|
|
|
my $offset = shift; |
196
|
|
|
|
|
|
|
return splice @$arg, $offset unless @_; |
197
|
|
|
|
|
|
|
my $length = shift; |
198
|
|
|
|
|
|
|
splice @$arg, $offset, $length, @_ |
199
|
|
|
|
|
|
|
}, |
200
|
|
|
|
|
|
|
split => sub { [ @_ > 2 ? split $_[1], $_[0], $_[2] : @_ > 1 ? split $_[1], $_[0] : split ' ', $_[0] ] }, |
201
|
|
|
|
|
|
|
_xlist(1, 'sprintf'), |
202
|
|
|
|
|
|
|
_scalar('sqrt'), |
203
|
|
|
|
|
|
|
_scalar('srand'), |
204
|
|
|
|
|
|
|
_scalar('stat'), |
205
|
|
|
|
|
|
|
_fixed_opt(2, 2, 'substr'), |
206
|
|
|
|
|
|
|
_fixed(2, 'symlink'), |
207
|
|
|
|
|
|
|
syscall => sub { my $arg = shift; syscall $arg, @_ }, |
208
|
|
|
|
|
|
|
system => sub { |
209
|
|
|
|
|
|
|
my $prog = shift; |
210
|
|
|
|
|
|
|
@_ ? system { $prog } @_ : |
211
|
|
|
|
|
|
|
ref($prog) eq 'ARRAY' ? system @$prog : |
212
|
|
|
|
|
|
|
system $prog |
213
|
|
|
|
|
|
|
}, |
214
|
|
|
|
|
|
|
_fixed(2, 'truncate'), |
215
|
|
|
|
|
|
|
_scalar('uc'), |
216
|
|
|
|
|
|
|
_scalar('ucfirst'), |
217
|
|
|
|
|
|
|
_scalar('umask'), |
218
|
|
|
|
|
|
|
_scalar('unlink'), |
219
|
|
|
|
|
|
|
unpack => sub { unpack $_[1], $_[0] }, |
220
|
|
|
|
|
|
|
unshift => sub { my $arg = shift; unshift @$arg, @_ }, |
221
|
|
|
|
|
|
|
_xlist(2, 'utime'), |
222
|
|
|
|
|
|
|
_hxa('values'), |
223
|
|
|
|
|
|
|
vec => sub :lvalue { @_ > 3 ? vec($_[0], $_[1], $_[2]) = $_[3] : vec($_[0], $_[1], $_[2]) }, |
224
|
|
|
|
|
|
|
_fixed(2, 'waitpid'), |
225
|
|
|
|
|
|
|
waitpid => sub { waitpid $_[0], @_ > 1 ? $_[1] : 0 }, |
226
|
|
|
|
|
|
|
_scalar('warn'), |
227
|
|
|
|
|
|
|
); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
our @EXPORT = map '$_' . $_, keys %functions; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
for my $k (keys %functions) { |
232
|
|
|
|
|
|
|
my $v = $functions{$k}; |
233
|
2
|
|
|
2
|
|
18
|
my $svref = do { no strict 'refs'; \${"_$k"} }; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
266
|
|
234
|
|
|
|
|
|
|
$$svref = $v; |
235
|
|
|
|
|
|
|
Internals::SvREADONLY($$svref, 1) if defined &Internals::SvREADONLY; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
'ok' |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
__END__ |