line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Variable;
|
2
|
1
|
|
|
1
|
|
16510
|
use strict; use warnings FATAL => 'all';
|
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
409
|
use parent 'Exporter';
|
|
1
|
|
|
|
|
273
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
52
|
use 5.008;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
1
|
|
|
1
|
|
4
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
6
|
1
|
|
|
1
|
|
4
|
use Scalar::Util 'weaken';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
120
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.001'; # <== update version in pod
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT;
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $NS = {};
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
push @EXPORT, 'public';
|
15
|
|
|
|
|
|
|
sub public
|
16
|
|
|
|
|
|
|
{
|
17
|
2
|
|
|
2
|
0
|
1642
|
my @names = @_;
|
18
|
2
|
|
|
|
|
7
|
my $package = (caller)[0];
|
19
|
2
|
|
|
|
|
5
|
foreach my $name (@names)
|
20
|
|
|
|
|
|
|
{
|
21
|
1
|
|
|
1
|
|
4
|
no strict 'refs';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
98
|
|
22
|
2
|
|
|
|
|
3
|
*{$package.'::'.$name } = get_public_variable($package, $name);
|
|
2
|
|
|
|
|
12
|
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
push @EXPORT, 'protected';
|
27
|
|
|
|
|
|
|
sub protected
|
28
|
|
|
|
|
|
|
{
|
29
|
2
|
|
|
2
|
0
|
7
|
my @names = @_;
|
30
|
2
|
|
|
|
|
4
|
my $package = (caller)[0];
|
31
|
2
|
|
|
|
|
2
|
foreach my $name (@names)
|
32
|
|
|
|
|
|
|
{
|
33
|
1
|
|
|
1
|
|
6
|
no strict 'refs';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
115
|
|
34
|
2
|
|
|
|
|
5
|
*{$package.'::'.$name } = get_protected_variable($package, $name);
|
|
2
|
|
|
|
|
8
|
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
push @EXPORT, 'private';
|
39
|
|
|
|
|
|
|
sub private
|
40
|
|
|
|
|
|
|
{
|
41
|
2
|
|
|
2
|
0
|
6
|
my @names = @_;
|
42
|
2
|
|
|
|
|
4
|
my $package = (caller)[0];
|
43
|
2
|
|
|
|
|
4
|
foreach my $name (@names)
|
44
|
|
|
|
|
|
|
{
|
45
|
1
|
|
|
1
|
|
4
|
no strict 'refs';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
321
|
|
46
|
2
|
|
|
|
|
5
|
*{$package.'::'.$name } = get_private_variable($package, $name);
|
|
2
|
|
|
|
|
9
|
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_public_variable($$)
|
51
|
|
|
|
|
|
|
{
|
52
|
2
|
|
|
2
|
0
|
3
|
my( $package, $name ) = @_;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return sub: lvalue
|
55
|
|
|
|
|
|
|
{
|
56
|
6
|
|
|
6
|
|
294
|
my $self = shift;
|
57
|
6
|
100
|
66
|
|
|
29
|
if(
|
58
|
|
|
|
|
|
|
not exists $NS->{$self}
|
59
|
|
|
|
|
|
|
or not defined $NS->{$self}->{' self'}
|
60
|
|
|
|
|
|
|
)
|
61
|
|
|
|
|
|
|
{
|
62
|
2
|
|
|
|
|
7
|
$NS->{$self} = {
|
63
|
|
|
|
|
|
|
' self' => $self
|
64
|
|
|
|
|
|
|
};
|
65
|
2
|
|
|
|
|
9
|
weaken $NS->{$self}->{' self'};
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
23
|
$NS->{$self}->{$name};
|
69
|
2
|
|
|
|
|
10
|
};
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_protected_variable($$)
|
73
|
|
|
|
|
|
|
{
|
74
|
2
|
|
|
2
|
0
|
2
|
my( $package, $name ) = @_;
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return sub: lvalue
|
77
|
|
|
|
|
|
|
{
|
78
|
14
|
|
|
14
|
|
1470
|
my $self = shift;
|
79
|
14
|
50
|
33
|
|
|
61
|
if(
|
80
|
|
|
|
|
|
|
not exists $NS->{$self}
|
81
|
|
|
|
|
|
|
or not defined $NS->{$self}->{' self'}
|
82
|
|
|
|
|
|
|
)
|
83
|
|
|
|
|
|
|
{
|
84
|
0
|
|
|
|
|
0
|
$NS->{$self} = {
|
85
|
|
|
|
|
|
|
' self' => $self
|
86
|
|
|
|
|
|
|
};
|
87
|
0
|
|
|
|
|
0
|
weaken $NS->{$self}->{' self'};
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
14
|
100
|
|
|
|
670
|
croak sprintf(
|
91
|
|
|
|
|
|
|
"Access violation: protected variable %s of %s available only to class or subclasses, but not %s."
|
92
|
|
|
|
|
|
|
, $name
|
93
|
|
|
|
|
|
|
, $package
|
94
|
|
|
|
|
|
|
, caller ) if not caller->isa($package);
|
95
|
|
|
|
|
|
|
|
96
|
8
|
|
|
|
|
29
|
$NS->{$self}->{$name};
|
97
|
2
|
|
|
|
|
7
|
};
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_private_variable($$)
|
101
|
|
|
|
|
|
|
{
|
102
|
2
|
|
|
2
|
0
|
2
|
my( $package, $name ) = @_;
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return sub: lvalue
|
105
|
|
|
|
|
|
|
{
|
106
|
14
|
|
|
14
|
|
1829
|
my $self = shift;
|
107
|
14
|
50
|
33
|
|
|
64
|
if(
|
108
|
|
|
|
|
|
|
not exists $NS->{$self}
|
109
|
|
|
|
|
|
|
or not defined $NS->{$self}->{' self'}
|
110
|
|
|
|
|
|
|
)
|
111
|
|
|
|
|
|
|
{
|
112
|
0
|
|
|
|
|
0
|
$NS->{$self} = {
|
113
|
|
|
|
|
|
|
' self' => $self
|
114
|
|
|
|
|
|
|
};
|
115
|
0
|
|
|
|
|
0
|
weaken $NS->{$self}->{' self'};
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
14
|
100
|
|
|
|
756
|
croak sprintf(
|
119
|
|
|
|
|
|
|
"Access violation: private variable %s of %s available only to class itself, not %s."
|
120
|
|
|
|
|
|
|
, $name
|
121
|
|
|
|
|
|
|
, $package
|
122
|
|
|
|
|
|
|
, caller ) if caller ne $package;
|
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
37
|
$NS->{$self}->{$name};
|
125
|
2
|
|
|
|
|
7
|
};
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1;
|
129
|
|
|
|
|
|
|
__END__
|