line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Accessor::Lite; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3244
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
210
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use Carp (); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
2074
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub import { |
10
|
5
|
|
|
5
|
|
55
|
shift; |
11
|
5
|
|
|
|
|
19
|
my %args = @_; |
12
|
5
|
|
|
|
|
14
|
my $pkg = caller(0); |
13
|
5
|
|
|
|
|
28
|
my %key_ctor = ( |
14
|
|
|
|
|
|
|
rw => \&_mk_accessors, |
15
|
|
|
|
|
|
|
ro => \&_mk_ro_accessors, |
16
|
|
|
|
|
|
|
wo => \&_mk_wo_accessors, |
17
|
|
|
|
|
|
|
); |
18
|
5
|
|
|
|
|
56
|
for my $key (sort keys %key_ctor) { |
19
|
14
|
100
|
|
|
|
182
|
if (defined $args{$key}) { |
20
|
4
|
100
|
|
|
|
239
|
Carp::croak "value of the '$key' parameter should be an arrayref" |
21
|
|
|
|
|
|
|
unless ref($args{$key}) eq 'ARRAY'; |
22
|
3
|
|
|
|
|
19
|
$key_ctor{$key}->($pkg, @{$args{$key}}); |
|
3
|
|
|
|
|
9
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
4
|
100
|
|
|
|
17
|
_mk_new($pkg) |
26
|
|
|
|
|
|
|
if $args{new}; |
27
|
4
|
|
|
|
|
70
|
1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub mk_new_and_accessors { |
31
|
1
|
|
|
1
|
1
|
852
|
(undef, my @properties) = @_; |
32
|
1
|
|
|
|
|
3
|
my $pkg = caller(0); |
33
|
1
|
|
|
|
|
3
|
_mk_new($pkg); |
34
|
1
|
|
|
|
|
3
|
_mk_accessors($pkg, @properties); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub mk_new { |
38
|
0
|
|
|
0
|
1
|
0
|
my $pkg = caller(0); |
39
|
0
|
|
|
|
|
0
|
_mk_new($pkg); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub mk_accessors { |
43
|
1
|
|
|
1
|
1
|
931
|
(undef, my @properties) = @_; |
44
|
1
|
|
|
|
|
2
|
my $pkg = caller(0); |
45
|
1
|
|
|
|
|
4
|
_mk_accessors($pkg, @properties); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub mk_ro_accessors { |
49
|
1
|
|
|
1
|
1
|
6
|
(undef, my @properties) = @_; |
50
|
1
|
|
|
|
|
3
|
my $pkg = caller(0); |
51
|
1
|
|
|
|
|
5
|
_mk_ro_accessors($pkg, @properties); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub mk_wo_accessors { |
55
|
1
|
|
|
1
|
1
|
6
|
(undef, my @properties) = @_; |
56
|
1
|
|
|
|
|
2
|
my $pkg = caller(0); |
57
|
1
|
|
|
|
|
4
|
_mk_wo_accessors($pkg, @properties); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _mk_new { |
61
|
2
|
|
|
2
|
|
4
|
my $pkg = shift; |
62
|
4
|
|
|
4
|
|
43
|
no strict 'refs'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
395
|
|
63
|
2
|
|
|
|
|
5
|
*{$pkg . '::new'} = __m_new($pkg); |
|
2
|
|
|
|
|
14
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _mk_accessors { |
67
|
3
|
|
|
3
|
|
6
|
my $pkg = shift; |
68
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
374
|
|
69
|
3
|
|
|
|
|
8
|
for my $n (@_) { |
70
|
7
|
|
|
|
|
18
|
*{$pkg . '::' . $n} = __m($n); |
|
7
|
|
|
|
|
48
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub _mk_ro_accessors { |
75
|
2
|
|
|
2
|
|
4
|
my $pkg = shift; |
76
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
339
|
|
77
|
2
|
|
|
|
|
4
|
for my $n (@_) { |
78
|
2
|
|
|
|
|
6
|
*{$pkg . '::' . $n} = __m_ro($pkg, $n); |
|
2
|
|
|
|
|
20
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _mk_wo_accessors { |
83
|
2
|
|
|
2
|
|
4
|
my $pkg = shift; |
84
|
4
|
|
|
4
|
|
25
|
no strict 'refs'; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
354
|
|
85
|
2
|
|
|
|
|
5
|
for my $n (@_) { |
86
|
2
|
|
|
|
|
7
|
*{$pkg . '::' . $n} = __m_wo($pkg, $n); |
|
2
|
|
|
|
|
16
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub __m_new { |
91
|
2
|
|
|
2
|
|
3
|
my $pkg = shift; |
92
|
4
|
|
|
4
|
|
20
|
no strict 'refs'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1979
|
|
93
|
|
|
|
|
|
|
return sub { |
94
|
2
|
|
|
2
|
|
381
|
my $klass = shift; |
95
|
0
|
|
|
|
|
0
|
bless { |
96
|
2
|
50
|
33
|
|
|
38
|
(@_ == 1 && ref($_[0]) eq 'HASH' ? %{$_[0]} : @_), |
97
|
|
|
|
|
|
|
}, $klass; |
98
|
2
|
|
|
|
|
9
|
}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub __m { |
102
|
7
|
|
|
7
|
|
16
|
my $n = shift; |
103
|
|
|
|
|
|
|
sub { |
104
|
12
|
100
|
|
12
|
|
1898
|
return $_[0]->{$n} if @_ == 1; |
105
|
3
|
100
|
|
|
|
15
|
return $_[0]->{$n} = $_[1] if @_ == 2; |
106
|
1
|
|
|
|
|
10
|
shift->{$n} = \@_; |
107
|
7
|
|
|
|
|
25
|
}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub __m_ro { |
111
|
2
|
|
|
2
|
|
4
|
my ($pkg, $n) = @_; |
112
|
|
|
|
|
|
|
sub { |
113
|
3
|
100
|
|
3
|
|
13
|
if (@_ == 1) { |
114
|
2
|
50
|
|
|
|
15
|
return $_[0]->{$n} if @_ == 1; |
115
|
|
|
|
|
|
|
} else { |
116
|
1
|
|
|
|
|
3
|
my $caller = caller(0); |
117
|
1
|
|
|
|
|
216
|
Carp::croak("'$caller' cannot access the value of '$n' on objects of class '$pkg'"); |
118
|
|
|
|
|
|
|
} |
119
|
2
|
|
|
|
|
11
|
}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub __m_wo { |
123
|
2
|
|
|
2
|
|
5
|
my ($pkg, $n) = @_; |
124
|
|
|
|
|
|
|
sub { |
125
|
4
|
100
|
|
4
|
|
7175
|
if (@_ == 1) { |
126
|
1
|
|
|
|
|
3
|
my $caller = caller(0); |
127
|
1
|
|
|
|
|
135
|
Carp::croak( "'$caller' cannot alter the value of '$n' on objects of class '$pkg'") |
128
|
|
|
|
|
|
|
} else { |
129
|
3
|
100
|
|
|
|
17
|
return $_[0]->{$n} = $_[1] if @_ == 2; |
130
|
1
|
|
|
|
|
10
|
shift->{$n} = \@_; |
131
|
|
|
|
|
|
|
} |
132
|
2
|
|
|
|
|
8
|
}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |