line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Variable;
|
2
|
1
|
|
|
1
|
|
16100
|
use 5.008;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; use warnings FATAL => 'all';
|
|
1
|
|
|
1
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
4
|
use Exporter 'import';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
3
|
use Carp;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
6
|
1
|
|
|
1
|
|
5
|
use Scalar::Util 'weaken';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
134
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.002'; # <== 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
|
2430
|
my @names = @_;
|
18
|
2
|
|
|
|
|
6
|
my $package = (caller)[0];
|
19
|
2
|
|
|
|
|
4
|
foreach my $name (@names)
|
20
|
|
|
|
|
|
|
{
|
21
|
1
|
|
|
1
|
|
4
|
no strict 'refs';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
99
|
|
22
|
2
|
|
|
|
|
6
|
*{$package.'::'.$name } = get_public_variable($package, $name);
|
|
2
|
|
|
|
|
13
|
|
23
|
|
|
|
|
|
|
}
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
push @EXPORT, 'protected';
|
27
|
|
|
|
|
|
|
sub protected($;)
|
28
|
|
|
|
|
|
|
{
|
29
|
2
|
|
|
2
|
0
|
8
|
my @names = @_;
|
30
|
2
|
|
|
|
|
4
|
my $package = (caller)[0];
|
31
|
2
|
|
|
|
|
4
|
foreach my $name (@names)
|
32
|
|
|
|
|
|
|
{
|
33
|
1
|
|
|
1
|
|
4
|
no strict 'refs';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
144
|
|
34
|
2
|
|
|
|
|
6
|
*{$package.'::'.$name } = get_protected_variable($package, $name);
|
|
2
|
|
|
|
|
9
|
|
35
|
|
|
|
|
|
|
}
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
push @EXPORT, 'private';
|
39
|
|
|
|
|
|
|
sub private($;)
|
40
|
|
|
|
|
|
|
{
|
41
|
2
|
|
|
2
|
0
|
6
|
my @names = @_;
|
42
|
2
|
|
|
|
|
5
|
my $package = (caller)[0];
|
43
|
2
|
|
|
|
|
3
|
foreach my $name (@names)
|
44
|
|
|
|
|
|
|
{
|
45
|
1
|
|
|
1
|
|
6
|
no strict 'refs';
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
430
|
|
46
|
2
|
|
|
|
|
4
|
*{$package.'::'.$name } = get_private_variable($package, $name);
|
|
2
|
|
|
|
|
9
|
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_public_variable($$)
|
51
|
|
|
|
|
|
|
{
|
52
|
2
|
|
|
2
|
0
|
4
|
my( $package, $name ) = @_;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return sub: lvalue
|
55
|
|
|
|
|
|
|
{
|
56
|
6
|
|
|
6
|
|
346
|
my $self = shift;
|
57
|
6
|
100
|
66
|
|
|
34
|
if(
|
58
|
|
|
|
|
|
|
not exists $NS->{$self}
|
59
|
|
|
|
|
|
|
or not defined $NS->{$self}->{' self'}
|
60
|
|
|
|
|
|
|
)
|
61
|
|
|
|
|
|
|
{
|
62
|
2
|
|
|
|
|
11
|
$NS->{$self} = {
|
63
|
|
|
|
|
|
|
' self' => $self
|
64
|
|
|
|
|
|
|
};
|
65
|
2
|
|
|
|
|
12
|
weaken $NS->{$self}->{' self'};
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
405
|
$NS->{$self}->{$name};
|
69
|
2
|
|
|
|
|
9
|
};
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_protected_variable($$)
|
73
|
|
|
|
|
|
|
{
|
74
|
2
|
|
|
2
|
0
|
3
|
my( $package, $name ) = @_;
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return sub: lvalue
|
77
|
|
|
|
|
|
|
{
|
78
|
14
|
|
|
14
|
|
1592
|
my $self = shift;
|
79
|
14
|
50
|
33
|
|
|
72
|
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
|
50
|
|
|
587
|
croak sprintf(
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
91
|
|
|
|
|
|
|
"Access violation: protected variable %s of %s available only to class or subclasses, but not %s."
|
92
|
|
|
|
|
|
|
, $name || 'undefined'
|
93
|
|
|
|
|
|
|
, $package || 'undefined'
|
94
|
|
|
|
|
|
|
, caller() || 'undefined' ) if not caller()->isa($package);
|
95
|
|
|
|
|
|
|
|
96
|
8
|
|
|
|
|
41
|
$NS->{$self}->{$name};
|
97
|
2
|
|
|
|
|
10
|
};
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub get_private_variable($$)
|
101
|
|
|
|
|
|
|
{
|
102
|
2
|
|
|
2
|
0
|
3
|
my( $package, $name ) = @_;
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
return sub: lvalue
|
105
|
|
|
|
|
|
|
{
|
106
|
14
|
|
|
14
|
|
1897
|
my $self = shift;
|
107
|
14
|
50
|
33
|
|
|
94
|
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
|
50
|
|
|
915
|
croak sprintf(
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
119
|
|
|
|
|
|
|
"Access violation: private variable %s of %s available only to class itself, not %s."
|
120
|
|
|
|
|
|
|
, $name || 'undefined'
|
121
|
|
|
|
|
|
|
, $package || 'undefined'
|
122
|
|
|
|
|
|
|
, caller() || 'undefined' ) if caller() ne $package;
|
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
49
|
$NS->{$self}->{$name};
|
125
|
2
|
|
|
|
|
6
|
};
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1;
|
130
|
|
|
|
|
|
|
__END__
|