line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Accessor::Faster; |
2
|
3
|
|
|
3
|
|
2963
|
use base 'Class::Accessor'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
224
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1708
|
|
4
|
|
|
|
|
|
|
$Class::Accessor::Faster::VERSION = '0.34'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my %slot; |
7
|
|
|
|
|
|
|
sub _slot { |
8
|
26
|
|
|
26
|
|
31
|
my($class, $field) = @_; |
9
|
26
|
|
|
|
|
44
|
my $n = $slot{$class}->{$field}; |
10
|
26
|
100
|
|
|
|
54
|
return $n if defined $n; |
11
|
16
|
|
|
|
|
17
|
$n = keys %{$slot{$class}}; |
|
16
|
|
|
|
|
30
|
|
12
|
16
|
|
|
|
|
36
|
$slot{$class}->{$field} = $n; |
13
|
16
|
|
|
|
|
28
|
return $n; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
4
|
|
|
4
|
1
|
3676
|
my($proto, $fields) = @_; |
18
|
4
|
|
33
|
|
|
29
|
my($class) = ref $proto || $proto; |
19
|
4
|
|
|
|
|
33
|
my $self = bless [], $class; |
20
|
|
|
|
|
|
|
|
21
|
4
|
100
|
|
|
|
15
|
$fields = {} unless defined $fields; |
22
|
4
|
|
|
|
|
16
|
for my $k (keys %$fields) { |
23
|
8
|
|
|
|
|
20
|
my $n = $class->_slot($k); |
24
|
8
|
|
|
|
|
42
|
$self->[$n] = $fields->{$k}; |
25
|
|
|
|
|
|
|
} |
26
|
4
|
|
|
|
|
11
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub make_accessor { |
30
|
6
|
|
|
6
|
1
|
10
|
my($class, $field) = @_; |
31
|
6
|
|
|
|
|
14
|
my $n = $class->_slot($field); |
32
|
|
|
|
|
|
|
return sub { |
33
|
12
|
100
|
|
12
|
|
1267
|
return $_[0]->[$n] if scalar(@_) == 1; |
34
|
4
|
100
|
|
|
|
17
|
return $_[0]->[$n] = scalar(@_) == 2 ? $_[1] : [@_[1..$#_]]; |
35
|
6
|
|
|
|
|
28
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub make_ro_accessor { |
39
|
6
|
|
|
6
|
1
|
9
|
my($class, $field) = @_; |
40
|
6
|
|
|
|
|
19
|
my $n = $class->_slot($field); |
41
|
|
|
|
|
|
|
return sub { |
42
|
6
|
100
|
|
6
|
|
33
|
return $_[0]->[$n] if @_ == 1; |
43
|
1
|
|
|
|
|
3
|
my $caller = caller; |
44
|
1
|
|
|
|
|
13
|
$_[0]->_croak("'$caller' cannot alter the value of '$field' on objects of class '$class'"); |
45
|
6
|
|
|
|
|
26
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub make_wo_accessor { |
49
|
6
|
|
|
6
|
1
|
8
|
my($class, $field) = @_; |
50
|
6
|
|
|
|
|
14
|
my $n = $class->_slot($field); |
51
|
|
|
|
|
|
|
return sub { |
52
|
5
|
100
|
|
5
|
|
483
|
if (@_ == 1) { |
53
|
1
|
|
|
|
|
3
|
my $caller = caller; |
54
|
1
|
|
|
|
|
8
|
$_[0]->_croak("'$caller' cannot access the value of '$field' on objects of class '$class'"); |
55
|
|
|
|
|
|
|
} else { |
56
|
4
|
100
|
|
|
|
19
|
return $_[0]->[$n] = $_[1] if @_ == 2; |
57
|
1
|
|
|
|
|
4
|
return (shift)->[$n] = \@_; |
58
|
|
|
|
|
|
|
} |
59
|
6
|
|
|
|
|
38
|
}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |