line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#############################################################################
|
2
|
|
|
|
|
|
|
## Name: MultiValue.pm
|
3
|
|
|
|
|
|
|
## Purpose: Scalar::MultiValue
|
4
|
|
|
|
|
|
|
## Author: Graciliano M. P.
|
5
|
|
|
|
|
|
|
## Modified by:
|
6
|
|
|
|
|
|
|
## Created: 2004-08-31
|
7
|
|
|
|
|
|
|
## RCS-ID:
|
8
|
|
|
|
|
|
|
## Copyright: (c) 2004 Graciliano M. P.
|
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or
|
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself
|
11
|
|
|
|
|
|
|
#############################################################################
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Scalar::MultiValue ;
|
14
|
1
|
|
|
1
|
|
8348
|
use 5.006 ;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use strict qw(vars);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
no warnings ;
|
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
46
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA) ;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = '0.03' ;
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@ISA = qw(Object::MultiType) ;
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
###########
|
27
|
|
|
|
|
|
|
# REQUIRE #
|
28
|
|
|
|
|
|
|
###########
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
1019
|
use Object::MultiType ;
|
|
1
|
|
|
|
|
6628
|
|
|
1
|
|
|
|
|
620
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#######
|
33
|
|
|
|
|
|
|
# NEW #
|
34
|
|
|
|
|
|
|
#######
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new {
|
37
|
2
|
|
|
2
|
1
|
149
|
my $class = shift ;
|
38
|
2
|
50
|
|
|
|
6
|
$class = ref($class) if ref($class) ;
|
39
|
|
|
|
|
|
|
|
40
|
2
|
100
|
|
|
|
15
|
my @values = ref $_[0] eq 'ARRAY' ? @{shift(@_)} : split(/\s/s , shift(@_)) ;
|
|
1
|
|
|
|
|
4
|
|
41
|
|
|
|
|
|
|
|
42
|
2
|
50
|
|
|
|
11
|
my %inf = ref $_[0] eq 'HASH' ? %{shift(@_)} : ( period => shift(@_) ) ;
|
|
0
|
|
|
|
|
0
|
|
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
15
|
my $this = Object::MultiType->new(
|
45
|
|
|
|
|
|
|
scalarsub => \&content ,
|
46
|
|
|
|
|
|
|
array => \@values ,
|
47
|
|
|
|
|
|
|
tiehash => 'Scalar::MultiValue::TieHash' ,
|
48
|
|
|
|
|
|
|
tieonuse => 1 ,
|
49
|
|
|
|
|
|
|
) ;
|
50
|
|
|
|
|
|
|
|
51
|
2
|
|
100
|
|
|
191
|
$$this->{period} = $inf{period} || 1 ;
|
52
|
2
|
50
|
|
|
|
11
|
$$this->{lastpos} = $inf{lastpos} ne '' ? $inf{lastpos} : 0 ;
|
53
|
2
|
|
|
|
|
6
|
$$this->{counter} = -1 ;
|
54
|
2
|
|
|
|
|
5
|
$$this->{last} = '' ;
|
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
9
|
bless($this,$class) ;
|
57
|
|
|
|
|
|
|
}
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
########
|
60
|
|
|
|
|
|
|
# LAST #
|
61
|
|
|
|
|
|
|
########
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub last {
|
64
|
0
|
|
|
0
|
1
|
0
|
my $this = shift ;
|
65
|
0
|
|
|
|
|
0
|
return $$this->{last} ;
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
###########
|
69
|
|
|
|
|
|
|
# CONTENT #
|
70
|
|
|
|
|
|
|
###########
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub content {
|
73
|
17
|
|
|
17
|
0
|
466
|
my $this = shift ;
|
74
|
|
|
|
|
|
|
|
75
|
17
|
50
|
|
|
|
96
|
if ( $$this->{period} eq '*' ) {
|
|
|
50
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
$$this->{lastpos} = int( rand(@{$$this->{a}}) ) ;
|
|
0
|
|
|
|
|
0
|
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
elsif ( $$this->{period} =~ /^\d+$/s ) {
|
79
|
17
|
|
|
|
|
26
|
++$$this->{counter} ;
|
80
|
|
|
|
|
|
|
|
81
|
17
|
100
|
|
|
|
50
|
if ( $$this->{counter} >= $$this->{period} ) {
|
82
|
9
|
|
|
|
|
12
|
$$this->{counter} = 0 ;
|
83
|
9
|
|
|
|
|
13
|
++$$this->{lastpos} ;
|
84
|
9
|
100
|
|
|
|
13
|
$$this->{lastpos} = 0 if $$this->{lastpos} > $#{$$this->{a}} ;
|
|
9
|
|
|
|
|
31
|
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
17
|
|
|
|
|
53
|
$$this->{last} = @{$$this->{a}}[ $$this->{lastpos} ] ;
|
|
17
|
|
|
|
|
42
|
|
89
|
|
|
|
|
|
|
|
90
|
17
|
|
|
|
|
165
|
return $$this->{last} ;
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#########
|
94
|
|
|
|
|
|
|
# RESET #
|
95
|
|
|
|
|
|
|
#########
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub reset {
|
98
|
1
|
|
|
1
|
1
|
10
|
my $this = shift ;
|
99
|
1
|
|
|
|
|
4
|
$$this->{counter} = -1 ;
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
##########
|
103
|
|
|
|
|
|
|
# PERIOD #
|
104
|
|
|
|
|
|
|
##########
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub period {
|
107
|
0
|
|
|
0
|
1
|
0
|
my $this = shift ;
|
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
0
|
if ( @_ ) {
|
110
|
0
|
|
|
|
|
0
|
$$this->{period} = shift ;
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
return $$this->{period} ;
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
###############################
|
117
|
|
|
|
|
|
|
# SCALAR::MULTIVALUE::TIEHASH #
|
118
|
|
|
|
|
|
|
###############################
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
package Scalar::MultiValue::TieHash ;
|
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
1
|
|
11
|
use strict qw(vars);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
569
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub TIEHASH {
|
125
|
1
|
|
|
1
|
|
20
|
my $class = shift ;
|
126
|
1
|
|
|
|
|
2
|
my $multi = shift ;
|
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
|
|
3
|
my $this = { h => $multi } ;
|
129
|
1
|
|
|
|
|
6
|
bless($this,$class) ;
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub FETCH {
|
133
|
2
|
|
|
2
|
|
30
|
my $this = shift ;
|
134
|
2
|
|
|
|
|
4
|
my $key = shift ;
|
135
|
2
|
|
|
|
|
14
|
return $this->{h}{$key} ;
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub STORE {
|
139
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
140
|
0
|
|
|
|
|
|
my $key = shift ;
|
141
|
0
|
|
|
|
|
|
return $this->{h}{$key} = $_[0] ;
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub DELETE {
|
145
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
146
|
0
|
|
|
|
|
|
my $key = shift ;
|
147
|
0
|
|
|
|
|
|
return delete $this->{h}{$key} ;
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub EXISTS {
|
151
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
152
|
0
|
|
|
|
|
|
my $key = shift ;
|
153
|
0
|
|
|
|
|
|
return exists $this->{h}{$key} ;
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub FIRSTKEY {
|
157
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
158
|
0
|
|
|
|
|
|
my $key = shift ;
|
159
|
0
|
|
|
|
|
|
return (keys %{$this->{h}})[0] ;
|
|
0
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub NEXTKEY {
|
163
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
164
|
0
|
|
|
|
|
|
my $keylast = shift ;
|
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $ret_next ;
|
167
|
0
|
|
|
|
|
|
foreach my $keys_i ( keys %{$this->{h}} ) {
|
|
0
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
if ($ret_next) { return $keys_i ;}
|
|
0
|
|
|
|
|
|
|
169
|
0
|
0
|
0
|
|
|
|
if ($keys_i eq $keylast || !defined $keylast) { $ret_next = 1 ;}
|
|
0
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
}
|
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
return undef ;
|
173
|
|
|
|
|
|
|
}
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub CLEAR {
|
176
|
0
|
|
|
0
|
|
|
my $this = shift ;
|
177
|
0
|
|
|
|
|
|
%{$this->{h}} = () ;
|
|
0
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return ;
|
179
|
|
|
|
|
|
|
}
|
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
0
|
|
|
sub UNTIE {}
|
182
|
0
|
|
|
0
|
|
|
sub DESTROY {}
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
#######
|
185
|
|
|
|
|
|
|
# END #
|
186
|
|
|
|
|
|
|
#######
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1;
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__
|