line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Sub; ## no critic (TidyCode)
|
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
257694
|
use strict;
|
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
175
|
|
4
|
5
|
|
|
5
|
|
27
|
use warnings;
|
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
222
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001';
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
25
|
use Carp qw(confess);
|
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
288
|
|
9
|
5
|
|
|
5
|
|
5154
|
use Params::Validate qw(:all);
|
|
5
|
|
|
|
|
74570
|
|
|
5
|
|
|
|
|
2412
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## no critic (ArgUnpacking)
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub TIEHASH {
|
14
|
4
|
|
|
4
|
|
290
|
my ($class, $code_ref) = validate_pos(
|
15
|
|
|
|
|
|
|
@_,
|
16
|
|
|
|
|
|
|
{type => SCALAR},
|
17
|
|
|
|
|
|
|
{type => CODEREF, optional => 1},
|
18
|
|
|
|
|
|
|
);
|
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
20
|
my $scalar;
|
21
|
4
|
|
|
|
|
16
|
my $self = bless \$scalar, $class;
|
22
|
4
|
100
|
|
|
|
16
|
if ($code_ref) {
|
23
|
3
|
|
|
|
|
15
|
$self->config($code_ref);
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
4
|
|
|
|
|
19
|
return $self;
|
27
|
|
|
|
|
|
|
}
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# configure
|
30
|
|
|
|
|
|
|
sub config {
|
31
|
|
|
|
|
|
|
# object, parameter
|
32
|
8
|
|
|
8
|
1
|
4428
|
my ($self, $code_ref) = validate_pos(
|
33
|
|
|
|
|
|
|
@_,
|
34
|
|
|
|
|
|
|
{isa => __PACKAGE__},
|
35
|
|
|
|
|
|
|
{type => CODEREF, optional => 1},
|
36
|
|
|
|
|
|
|
);
|
37
|
|
|
|
|
|
|
|
38
|
6
|
|
|
|
|
24
|
my $previous_code_ref = ${$self};
|
|
6
|
|
|
|
|
17
|
|
39
|
6
|
100
|
|
|
|
19
|
if ($code_ref) {
|
40
|
5
|
|
|
|
|
8
|
${$self} = $code_ref;
|
|
5
|
|
|
|
|
10
|
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
30
|
return $previous_code_ref;
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# execute the code reference
|
47
|
|
|
|
|
|
|
sub FETCH {
|
48
|
|
|
|
|
|
|
# object, key
|
49
|
4
|
|
|
4
|
|
1434
|
my ($self, $key) = validate_pos(
|
50
|
|
|
|
|
|
|
@_,
|
51
|
|
|
|
|
|
|
{isa => __PACKAGE__},
|
52
|
|
|
|
|
|
|
{type => SCALAR | ARRAYREF},
|
53
|
|
|
|
|
|
|
);
|
54
|
|
|
|
|
|
|
|
55
|
4
|
100
|
|
|
|
15
|
${$self} or confess 'Call of method "config" is necessary';
|
|
4
|
|
|
|
|
46
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Several parameters to the subroutine will submit as reference on an array.
|
58
|
3
|
|
|
|
|
11
|
return ${$self}->(
|
|
2
|
|
|
|
|
4
|
|
59
|
|
|
|
|
|
|
ref $key eq 'ARRAY'
|
60
|
3
|
100
|
|
|
|
15
|
? @{$key}
|
61
|
|
|
|
|
|
|
: $key
|
62
|
|
|
|
|
|
|
);
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# $Id$
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1;
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__
|