line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sub::Lib; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14674
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
450
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
5
|
|
|
5
|
1
|
2378
|
my ($class, @args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
|
|
5
|
my $args; |
12
|
5
|
100
|
|
|
|
10
|
if(1 == @args) { |
13
|
2
|
100
|
|
|
|
9
|
die "reference argument to new() must be a HASH\n" |
14
|
|
|
|
|
|
|
unless 'HASH' eq ref $args[0]; |
15
|
1
|
|
|
|
|
2
|
$args = $args[0]; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
else { |
18
|
3
|
100
|
|
|
|
11
|
die "non-reference argument list to new() must have an even number of elements\n" |
19
|
|
|
|
|
|
|
unless 0 == @args % 2; |
20
|
2
|
|
|
|
|
5
|
$args = {@args}; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# \o/ Lobe den Abgrund |
24
|
3
|
|
|
|
|
3
|
my $self = bless do { |
25
|
3
|
|
|
|
|
3
|
my $_lib = { }; |
26
|
|
|
|
|
|
|
sub { |
27
|
15
|
|
|
15
|
|
876
|
my ($name, $sub) = @_; |
28
|
|
|
|
|
|
|
|
29
|
15
|
100
|
|
|
|
31
|
return $_lib |
30
|
|
|
|
|
|
|
unless defined $name; |
31
|
|
|
|
|
|
|
|
32
|
10
|
100
|
|
|
|
13
|
if(defined $sub) { |
33
|
3
|
100
|
|
|
|
14
|
die "sub-routine ($name) is not a sub-routine?\n" |
34
|
|
|
|
|
|
|
unless 'CODE' eq ref $sub; |
35
|
|
|
|
|
|
|
die "sub-routine ($name) already installed in library\n" |
36
|
2
|
100
|
|
|
|
9
|
if exists $_lib->{$name}; |
37
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
1
|
$_lib->{$name} = $sub; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
|
|
|
|
|
|
die "sub-routine ($name) not installed in library\n" |
42
|
7
|
100
|
|
|
|
20
|
unless exists $_lib->{$name}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
|
|
13
|
return $_lib->{$name}; |
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
|
|
12
|
}, $class; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->($_, $args->{$_}) |
50
|
3
|
|
|
|
|
10
|
for keys %$args; |
51
|
2
|
|
|
|
|
5
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub has { |
55
|
2
|
|
|
2
|
1
|
6
|
my ($self, $name) = @_; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
3
|
my $_lib = $self->(); |
58
|
2
|
|
|
|
|
7
|
return $_lib->{$name}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub run { |
62
|
1
|
|
|
1
|
1
|
280
|
my ($self, $name, @args) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
3
|
return $self->($name)->(@args); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub call { |
68
|
1
|
|
|
1
|
1
|
321
|
my ($self, $name, $object, @args) = @_; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
2
|
my $sub = $self->($name); |
71
|
1
|
|
|
|
|
3
|
return $object->$sub(@args); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub void { |
75
|
2
|
|
|
2
|
1
|
509
|
my ($self, $name) = @_; |
76
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
5
|
my $_lib = $self->(); |
78
|
|
|
|
|
|
|
my $sub = exists $_lib->{$name} |
79
|
|
|
|
|
|
|
? $_lib->{$name} |
80
|
1
|
|
|
1
|
|
5
|
: sub { return } |
81
|
2
|
100
|
|
|
|
9
|
; |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
5
|
return $sub; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub curry { |
87
|
1
|
|
|
1
|
1
|
2
|
my ($self, $name, @args) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
3
|
my $sub = $self->($name); |
90
|
1
|
|
|
1
|
|
4
|
return sub { $sub->(@args, @_) }; |
|
1
|
|
|
|
|
4
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub o { |
94
|
1
|
|
|
1
|
1
|
280
|
my ($self, $name, $object, @args) = @_; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
4
|
my $sub = $self->($name); |
97
|
1
|
|
|
1
|
|
4
|
return sub { $object->$sub(@args, @_) }; |
|
1
|
|
|
|
|
4
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub y { |
101
|
2
|
|
|
2
|
1
|
884
|
my ($self, $name, $sub, @args) = @_; |
102
|
|
|
|
|
|
|
|
103
|
2
|
100
|
|
|
|
9
|
die "code reference required for lambda\n" |
104
|
|
|
|
|
|
|
unless 'CODE' eq ref $sub; |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
1
|
|
2
|
return sub { $sub->( $self->($name), @args, @_ ) } |
107
|
1
|
|
|
|
|
4
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1 |
111
|
|
|
|
|
|
|
__END__ |