line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::PublicPrivate; |
2
|
1
|
|
|
1
|
|
1488
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# version |
5
|
|
|
|
|
|
|
our $VERSION = '0.82'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
8
|
|
|
|
|
|
|
# opening POD |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Class::PublicPrivate - Class with public keys with any name and a separate set |
14
|
|
|
|
|
|
|
of private keys |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
PublicPrivate is intended for use as a base class for other classes. Users of |
19
|
|
|
|
|
|
|
class based on PublicPrivate can assign any keys to the object hash without |
20
|
|
|
|
|
|
|
interfering with keys used internally. The private data can be accessed by |
21
|
|
|
|
|
|
|
retrieving the private hash with the C method. For example, the |
22
|
|
|
|
|
|
|
following code outputs two different values, one for the public value of |
23
|
|
|
|
|
|
|
C and another for the private value of C. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
package ExtendedClass; |
26
|
|
|
|
|
|
|
use base 'Class::PublicPrivate'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new{ |
29
|
|
|
|
|
|
|
my $class = shift; |
30
|
|
|
|
|
|
|
my $self = $class->SUPER::new(); |
31
|
|
|
|
|
|
|
my $private = $self->private; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# initialize one of the private properties |
34
|
|
|
|
|
|
|
$private->{'start'}=time(); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
package main; |
40
|
|
|
|
|
|
|
my ($var); |
41
|
|
|
|
|
|
|
$var = ExtendedClass->new(); |
42
|
|
|
|
|
|
|
$var->{'start'} = 1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
print $var->{'start'}, "\n"; |
45
|
|
|
|
|
|
|
print $var->private()->{'start'}, "\n"; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 INSTALLATION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Class::PublicPrivate can be installed with the usual routine: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
perl Makefile.PL |
52
|
|
|
|
|
|
|
make |
53
|
|
|
|
|
|
|
make test |
54
|
|
|
|
|
|
|
make install |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 YourClass->new(classname ,[initikey1=>initvalue [, ...]]) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns an instantiation of YourClass, where YourClass is a class that extends |
61
|
|
|
|
|
|
|
Class::PublicPrivate. Additional key=>value pairs are stored in the private |
62
|
|
|
|
|
|
|
hash. Programs that use your class can store any date directly in it w/o |
63
|
|
|
|
|
|
|
affecting the object's private data. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 $ob->private() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns a reference to the hash of private data. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 TERMS AND CONDITIONS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Copyright (c) 2015 by Miko O'Sullivan. All rights reserved. This program |
72
|
|
|
|
|
|
|
is free software; you can redistribute it and/or modify it under the same |
73
|
|
|
|
|
|
|
terms as Perl itself. This software comes with B of any kind. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Miko O'Sullivan |
78
|
|
|
|
|
|
|
F |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# |
83
|
|
|
|
|
|
|
# opening POD |
84
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
88
|
|
|
|
|
|
|
# new |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
sub new { |
91
|
1
|
|
|
1
|
1
|
174
|
my $class = shift; |
92
|
1
|
|
|
|
|
2
|
my (%nv, $self); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# reference nv in hash |
95
|
1
|
|
|
|
|
6
|
tie %nv, 'Class::PublicPrivate::Tie', @_; |
96
|
1
|
|
|
|
|
3
|
$self = bless(\%nv, $class); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# return |
99
|
1
|
|
|
|
|
2
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
# |
102
|
|
|
|
|
|
|
# new |
103
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
107
|
|
|
|
|
|
|
# private |
108
|
|
|
|
|
|
|
# returns the private hash |
109
|
|
|
|
|
|
|
# |
110
|
|
|
|
|
|
|
sub private { |
111
|
2
|
|
|
2
|
1
|
445
|
return (tied(%{$_[0]}))->{'private'}; |
|
2
|
|
|
|
|
8
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# private |
115
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
############################################################################### |
120
|
|
|
|
|
|
|
# Class::PublicPrivate::Tie |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
package Class::PublicPrivate::Tie; |
123
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
225
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub TIEHASH { |
126
|
1
|
|
|
1
|
|
2
|
my ($class, %opts) = @_; |
127
|
1
|
|
|
|
|
2
|
my $self = bless({}, $class); |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
50
|
|
|
12
|
$self->{'private'} = $opts{'private'} || {}; |
130
|
1
|
|
50
|
|
|
6
|
$self->{'public'} = $opts{'public'} || {}; |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
|
|
3
|
return $self; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub STORE { |
136
|
1
|
|
|
1
|
|
5
|
$_[0]->{'public'}->{$_[1]} = $_[2]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub FETCH { |
140
|
0
|
|
|
0
|
|
0
|
return $_[0]->{'public'}->{$_[1]}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub DELETE { |
144
|
0
|
|
|
0
|
|
0
|
delete $_[0]->{'public'}->{$_[1]}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub CLEAR { |
148
|
0
|
|
|
0
|
|
0
|
$_[0]->{'public'} = {}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub EXISTS { |
152
|
0
|
|
|
0
|
|
0
|
exists $_[0]->{'public'}->{$_[1]}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub FIRSTKEY { |
156
|
1
|
|
|
1
|
|
7
|
my $self = shift; |
157
|
1
|
|
|
|
|
1
|
my $a = keys(%{$self->{'public'}}); |
|
1
|
|
|
|
|
2
|
|
158
|
1
|
|
|
|
|
3
|
return $self->NEXTKEY; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub NEXTKEY { |
162
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
163
|
2
|
|
|
|
|
3
|
my $v = (each %{$self->{'public'}})[0]; |
|
2
|
|
|
|
|
4
|
|
164
|
2
|
|
|
|
|
7
|
return $v; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
# |
167
|
|
|
|
|
|
|
# Class::PublicPrivate::Tie |
168
|
|
|
|
|
|
|
############################################################################### |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# return |
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 VERSION |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Version: |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 HISTORY |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item Version 0.80, June 29, 2002 |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
First public release |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item Version 0.81 May 18, 2014 |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Minor tightening up of code. Fixed problems in packaging for CPAN. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item Version 0.82 January 2, 2015 |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Minor tidying up code formatting and POD. Modifed tests to include test names. |
195
|
|
|
|
|
|
|
Modifed files to use Unix style newlines, and to be encoded UTF-8. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |