line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Attribute::Curried; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14212
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
214641
|
use Attribute::Handlers; |
|
1
|
|
|
|
|
5479
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub UNIVERSAL::Curry :ATTR(CODE) { |
11
|
3
|
|
|
3
|
0
|
4449
|
my ($package, $symbol, $code, $name, $n) = @_; |
12
|
3
|
50
|
|
|
|
18
|
$n = $n->[0] if ref $n; |
13
|
3
|
|
|
|
|
13
|
local($^W) = 0; |
14
|
1
|
|
|
1
|
|
74
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
100
|
|
15
|
3
|
|
|
|
|
8
|
my $subname = $package . '::' . *{$symbol}{NAME}; |
|
3
|
|
|
|
|
11
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
50
|
|
|
|
19
|
if ($symbol eq 'ANON') { |
18
|
0
|
|
|
|
|
0
|
return; |
19
|
|
|
|
|
|
|
} |
20
|
3
|
50
|
33
|
|
|
26
|
unless (defined($n) && $n > 1) { |
21
|
0
|
|
|
|
|
0
|
warn "Usage: \"sub $subname :Curry(ARGS)\", ARGS > 1"; |
22
|
0
|
|
|
|
|
0
|
return; |
23
|
|
|
|
|
|
|
} |
24
|
3
|
|
|
|
|
5
|
undef *{$subname}; # to quiet warnings about prototypes |
|
3
|
|
|
|
|
15
|
|
25
|
3
|
|
|
|
|
11
|
*{$subname} = _curry($n, $code); |
|
3
|
|
|
|
|
22
|
|
26
|
1
|
|
|
1
|
|
4
|
} |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _curry { |
29
|
9
|
|
|
9
|
|
19
|
my ($n, $func, @args) = @_; |
30
|
|
|
|
|
|
|
return sub { |
31
|
14
|
|
|
14
|
|
719
|
my $narg = @_ + @args; |
32
|
14
|
50
|
|
|
|
33
|
if ($narg > $n) { |
|
|
100
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
die "$narg args to curried function (expects $n)."; |
34
|
|
|
|
|
|
|
} elsif ($narg < $n) { |
35
|
6
|
|
|
|
|
10
|
return _curry($n, $func, @args, @_); |
36
|
|
|
|
|
|
|
} else { |
37
|
8
|
|
|
|
|
19
|
return &$func(@args, @_); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
9
|
|
|
|
|
52
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
__END__ |