line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#+############################################################################## |
2
|
|
|
|
|
|
|
# # |
3
|
|
|
|
|
|
|
# File: Directory/Queue/Set.pm # |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# Description: object oriented interface to a set of Directory::Queue objects # |
6
|
|
|
|
|
|
|
# # |
7
|
|
|
|
|
|
|
#-############################################################################## |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# module definition |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Directory::Queue::Set; |
14
|
1
|
|
|
1
|
|
422
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
15
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
16
|
|
|
|
|
|
|
our $VERSION = "2.2"; |
17
|
|
|
|
|
|
|
our $REVISION = sprintf("%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# used modules |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use No::Worries::Die qw(dief); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# |
26
|
|
|
|
|
|
|
# return true if the given thing is a Directory::Queue object |
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _isdq ($) { |
30
|
4
|
|
|
4
|
|
7
|
my($thing) = @_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
33
|
|
|
30
|
return(ref($thing) && $thing->isa("Directory::Queue")); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# |
36
|
|
|
|
|
|
|
# object constructor |
37
|
|
|
|
|
|
|
# |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new : method { |
40
|
2
|
|
|
2
|
1
|
14
|
my($class, @list) = @_; |
41
|
2
|
|
|
|
|
2
|
my($self); |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
4
|
$self = {}; |
44
|
2
|
|
|
|
|
4
|
bless($self, $class); |
45
|
2
|
|
|
|
|
6
|
$self->add(@list); |
46
|
2
|
|
|
|
|
8
|
return($self); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# add one or more queues to the set |
51
|
|
|
|
|
|
|
# |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub add : method { |
54
|
3
|
|
|
3
|
1
|
6
|
my($self, @list) = @_; |
55
|
3
|
|
|
|
|
4
|
my($id); |
56
|
|
|
|
|
|
|
|
57
|
3
|
|
|
|
|
16
|
foreach my $dirq (@list) { |
58
|
3
|
50
|
|
|
|
7
|
dief("not a Directory::Queue object: %s", $dirq) unless _isdq($dirq); |
59
|
3
|
|
|
|
|
9
|
$id = $dirq->id(); |
60
|
|
|
|
|
|
|
dief("duplicate queue in set: %s", $dirq->path()) |
61
|
3
|
50
|
|
|
|
8
|
if $self->{dirq}{$id}; |
62
|
3
|
|
|
|
|
8
|
$self->{dirq}{$id} = $dirq->copy(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
# reset our iterator |
65
|
3
|
|
|
|
|
10
|
delete($self->{elt}); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# remove one or more queues from the set |
70
|
|
|
|
|
|
|
# |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub remove : method { |
73
|
1
|
|
|
1
|
1
|
7
|
my($self, @list) = @_; |
74
|
1
|
|
|
|
|
2
|
my($id); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
2
|
foreach my $dirq (@list) { |
77
|
1
|
50
|
|
|
|
2
|
dief("not a Directory::Queue object: %s", $dirq) unless _isdq($dirq); |
78
|
1
|
|
|
|
|
6
|
$id = $dirq->id(); |
79
|
|
|
|
|
|
|
dief("missing queue in set: %s", $dirq->path()) |
80
|
1
|
50
|
|
|
|
3
|
unless $self->{dirq}{$id}; |
81
|
1
|
|
|
|
|
4
|
delete($self->{dirq}{$id}); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
# reset our iterator |
84
|
1
|
|
|
|
|
3
|
delete($self->{elt}); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# |
88
|
|
|
|
|
|
|
# get the next element of the queue set |
89
|
|
|
|
|
|
|
# |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub next : method { ## no critic 'ProhibitBuiltinHomonyms' |
92
|
10
|
|
|
10
|
1
|
527
|
my($self) = @_; |
93
|
10
|
|
|
|
|
12
|
my($name, $min_elt, $min_id); |
94
|
|
|
|
|
|
|
|
95
|
10
|
50
|
|
|
|
22
|
return() unless $self->{elt}; |
96
|
10
|
|
|
|
|
13
|
foreach my $id (keys(%{ $self->{elt} })) { |
|
10
|
|
|
|
|
20
|
|
97
|
14
|
|
|
|
|
24
|
$name = substr($self->{elt}{$id}, -14); |
98
|
14
|
100
|
100
|
|
|
34
|
next if defined($min_elt) and $min_elt le $name; |
99
|
11
|
|
|
|
|
13
|
$min_elt = $name; |
100
|
11
|
|
|
|
|
14
|
$min_id = $id; |
101
|
|
|
|
|
|
|
} |
102
|
10
|
100
|
|
|
|
22
|
unless ($min_id) { |
103
|
2
|
|
|
|
|
4
|
delete($self->{elt}); |
104
|
2
|
|
|
|
|
6
|
return(); |
105
|
|
|
|
|
|
|
} |
106
|
8
|
|
|
|
|
10
|
$min_elt = $self->{elt}{$min_id}; |
107
|
8
|
|
|
|
|
20
|
$self->{elt}{$min_id} = $self->{dirq}{$min_id}->next(); |
108
|
8
|
100
|
|
|
|
16
|
delete($self->{elt}{$min_id}) unless $self->{elt}{$min_id}; |
109
|
8
|
|
|
|
|
30
|
return($self->{dirq}{$min_id}, $min_elt); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
# get the first element of the queue set |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub first : method { |
117
|
2
|
|
|
2
|
1
|
977
|
my($self) = @_; |
118
|
|
|
|
|
|
|
|
119
|
2
|
50
|
|
|
|
8
|
return() unless $self->{dirq}; |
120
|
2
|
|
|
|
|
4
|
delete($self->{elt}); |
121
|
2
|
|
|
|
|
3
|
foreach my $id (keys(%{ $self->{dirq} })) { |
|
2
|
|
|
|
|
6
|
|
122
|
4
|
|
|
|
|
20
|
$self->{elt}{$id} = $self->{dirq}{$id}->first(); |
123
|
4
|
50
|
|
|
|
11
|
delete($self->{elt}{$id}) unless $self->{elt}{$id}; |
124
|
|
|
|
|
|
|
} |
125
|
2
|
|
|
|
|
16
|
return($self->next()); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# |
129
|
|
|
|
|
|
|
# count the elements of the queue set |
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub count : method { |
133
|
3
|
|
|
3
|
1
|
9
|
my($self) = @_; |
134
|
3
|
|
|
|
|
3
|
my($count); |
135
|
|
|
|
|
|
|
|
136
|
3
|
100
|
|
|
|
10
|
return(0) unless $self->{dirq}; |
137
|
2
|
|
|
|
|
3
|
$count = 0; |
138
|
2
|
|
|
|
|
3
|
foreach my $id (keys(%{ $self->{dirq} })) { |
|
2
|
|
|
|
|
5
|
|
139
|
3
|
|
|
|
|
12
|
$count += $self->{dirq}{$id}->count(); |
140
|
|
|
|
|
|
|
} |
141
|
2
|
|
|
|
|
10
|
return($count); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |