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