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