line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: List.pm 1334 2003-08-13 13:07:42Z richardc $ |
2
|
18
|
|
|
18
|
|
93
|
use strict; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
725
|
|
3
|
|
|
|
|
|
|
package Siesta::List; |
4
|
18
|
|
|
18
|
|
14953
|
use UNIVERSAL::require; |
|
18
|
|
|
|
|
29062
|
|
|
18
|
|
|
|
|
180
|
|
5
|
18
|
|
|
18
|
|
492
|
use Siesta::DBI; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
1069
|
|
6
|
18
|
|
|
18
|
|
1065
|
use base 'Siesta::DBI'; |
|
18
|
|
|
|
|
34
|
|
|
18
|
|
|
|
|
2620
|
|
7
|
18
|
|
|
18
|
|
250
|
use Carp qw( croak ); |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
1863
|
|
8
|
18
|
|
|
18
|
|
18624
|
use POSIX qw( strftime ); |
|
18
|
|
|
|
|
133816
|
|
|
18
|
|
|
|
|
229
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->set_up_table('list'); |
10
|
|
|
|
|
|
|
__PACKAGE__->load_alias('name'); |
11
|
|
|
|
|
|
|
__PACKAGE__->has_a( owner => 'Siesta::Member' ); |
12
|
|
|
|
|
|
|
__PACKAGE__->has_many( members => [ 'Siesta::Subscription' => 'member' ] ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# this is a bit funny, never mind |
15
|
|
|
|
|
|
|
__PACKAGE__->has_many( _plugins => 'Siesta::Plugin', 'list', |
16
|
|
|
|
|
|
|
{ sort => 'rank' } ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Siesta::List - manipulate a list |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 ->new ( %hash ) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
1
|
0
|
sub new { shift->create({ @_ }) } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 ->name |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
the short name of the list |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 ->owner |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
the owner (a Siesta::Member) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 ->post_address |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
the email address that people post to send to this list. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# the address to use to post to pipline $foo |
47
|
|
|
|
|
|
|
sub address { |
48
|
9
|
|
|
9
|
0
|
11211
|
my $self = shift; |
49
|
9
|
|
|
|
|
21
|
my $pipeline = shift; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# XXX - hacky |
52
|
9
|
|
|
|
|
48
|
my $address = $self->post_address; |
53
|
9
|
50
|
33
|
|
|
2319
|
return $address if !$pipeline || $pipeline eq 'post'; |
54
|
9
|
|
|
|
|
100
|
$address =~ s/\@/-$pipeline\@/; |
55
|
9
|
|
|
|
|
107
|
return $address; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 ->return_path |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
the email address that bounces should come back to |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 ->members |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
all of the Ls subscribed to this list |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 ->prefs |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
all of the preferences associated with this list |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 ->is_member( $member ) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns true or false depending if member is a member of this |
73
|
|
|
|
|
|
|
list. This can take either a Member object or an email address. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_member { |
78
|
20
|
|
|
20
|
1
|
35116
|
my $self = shift; |
79
|
20
|
|
|
|
|
45
|
my $member = shift; |
80
|
|
|
|
|
|
|
|
81
|
20
|
100
|
|
|
|
331
|
$member = Siesta::Member->load( $member ) unless ref $member; |
82
|
20
|
100
|
|
|
|
83
|
return unless $member; |
83
|
17
|
|
|
|
|
1776
|
Siesta::Subscription->search( member => $member, list => $self ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 ->add_member( $member ) |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Adds a member to a list. This can take either a Member object |
90
|
|
|
|
|
|
|
or an email address. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub add_member { |
95
|
6
|
|
|
6
|
1
|
1926423
|
my $self = shift; |
96
|
6
|
|
|
|
|
20
|
my $member = shift; |
97
|
|
|
|
|
|
|
|
98
|
6
|
100
|
|
|
|
105
|
$member = Siesta::Member->find_or_create({ email => $member }) |
99
|
|
|
|
|
|
|
unless ref $member; |
100
|
6
|
50
|
|
|
|
29816
|
return if $self->is_member( $member ); |
101
|
6
|
|
|
|
|
22782
|
Siesta::Subscription->create({ member => $member, list => $self }); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 ->remove_member( $member ) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Removes a member from a list. This can take either a Member |
108
|
|
|
|
|
|
|
object or an email address. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub remove_member { |
113
|
6
|
|
|
6
|
1
|
6568
|
my $self = shift; |
114
|
6
|
|
|
|
|
15
|
my $member = shift; |
115
|
|
|
|
|
|
|
|
116
|
6
|
50
|
|
|
|
75
|
$member = Siesta::Member->load( $member ) unless ref $member; |
117
|
6
|
100
|
|
|
|
25
|
return unless $member; |
118
|
4
|
|
|
|
|
271
|
my ($record) = Siesta::Subscription->search( member => $member, |
119
|
|
|
|
|
|
|
list => $self ); |
120
|
4
|
100
|
|
|
|
21102
|
return unless $record; |
121
|
3
|
|
|
|
|
450
|
$record->delete; |
122
|
3
|
|
|
|
|
1541446
|
return 1; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 ->members |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns a list of all the members in the list (as Member objects) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 ->queues |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns a list of all processing queues associated with this list. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub queues { |
137
|
0
|
|
|
0
|
1
|
0
|
qw( post sub unsub ); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 ->plugins( [ $queue ] ) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns a list of all the plugins for a list (as Plugin objects). |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub plugins { |
148
|
53
|
|
|
53
|
1
|
1076236
|
my $self = shift; |
149
|
53
|
|
100
|
|
|
551
|
my $queue = shift || 'post'; |
150
|
|
|
|
|
|
|
# map from the raw accessor we set up into the correct classes |
151
|
53
|
|
|
|
|
612
|
return map { $_->promote } grep { $_->queue eq $queue } $self->_plugins; |
|
188
|
|
|
|
|
228245
|
|
|
192
|
|
|
|
|
320490
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 ->add_plugin( $queue => $plugin ) |
156
|
|
|
|
|
|
|
=head2 ->add_plugin( $queue => $plugin, $position ) |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Add a plugin to this lists processing queue $queue. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
$position is optional, and indiates the new index of the plugin. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub add_plugin { |
165
|
17
|
|
|
17
|
1
|
1290949
|
my $self = shift; |
166
|
17
|
|
|
|
|
51
|
my $queue = shift; |
167
|
17
|
|
|
|
|
44
|
my $plugin = shift; |
168
|
17
|
|
|
|
|
59
|
my $pos = shift; |
169
|
|
|
|
|
|
|
|
170
|
17
|
|
|
|
|
73
|
my $personal = ($plugin =~ s/^\+//); |
171
|
17
|
|
|
|
|
88
|
my @existing = $self->plugins( $queue ); |
172
|
108
|
|
|
|
|
167933
|
croak "can only add 1 instance of a plugin to a queue" |
173
|
17
|
50
|
|
|
|
32967
|
if grep { $_->name eq $plugin } @existing; |
174
|
|
|
|
|
|
|
|
175
|
17
|
100
|
66
|
|
|
20207
|
if ( defined $pos && $existing[ $pos - 1 ] ) { |
176
|
1
|
|
|
|
|
114
|
for (@existing) { # shuffle the others up |
177
|
2
|
50
|
|
|
|
20548
|
if ($_->rank >= $pos) { |
178
|
2
|
|
|
|
|
197
|
$_->rank( $_->rank + 1 ); |
179
|
2
|
|
|
|
|
849
|
$_->update; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
else { |
184
|
16
|
|
|
|
|
43
|
$pos = @existing + 1; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
17
|
|
|
|
|
23929
|
Siesta::Plugin->create({ queue => $queue, |
188
|
|
|
|
|
|
|
name => $plugin, |
189
|
|
|
|
|
|
|
rank => $pos, |
190
|
|
|
|
|
|
|
list => $self, |
191
|
|
|
|
|
|
|
personal => $personal, |
192
|
|
|
|
|
|
|
}); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 ->set_plugins( $queue => @plugins) |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Set the plugin processing queue for this list. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub set_plugins { |
203
|
7
|
|
|
7
|
1
|
71977
|
my $self = shift; |
204
|
7
|
|
|
|
|
23
|
my $queue = shift; |
205
|
7
|
|
|
|
|
16
|
my $i; |
206
|
7
|
|
|
|
|
23
|
my %new_rank = map { (my $name = $_) =~ s/^\+//; |
|
15
|
|
|
|
|
46
|
|
207
|
15
|
|
|
|
|
91
|
$name => { personal => $_ ne $name, |
208
|
|
|
|
|
|
|
rank => ++$i } |
209
|
|
|
|
|
|
|
} @_; |
210
|
|
|
|
|
|
|
|
211
|
7
|
50
|
|
|
|
67
|
die "'$queue' doesn't look like an queue id" unless $queue =~ /^[a-z]+$/; |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# first, delete the plugins that don't exist in the new order |
214
|
7
|
|
|
|
|
42
|
for ($self->plugins($queue)) { |
215
|
12
|
100
|
|
|
|
56908
|
$_->delete unless $new_rank{ $_->name }; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# then just add new ones |
219
|
7
|
|
|
|
|
51940
|
my %old = map { $_->name => 1 } $self->plugins($queue); |
|
9
|
|
|
|
|
9896
|
|
220
|
7
|
|
|
|
|
7353
|
for my $plugin (keys %new_rank) { |
221
|
15
|
100
|
|
|
|
56254
|
next if $old{ $plugin }; |
222
|
6
|
|
|
|
|
165
|
Siesta::Plugin->create({ name => $plugin, |
223
|
|
|
|
|
|
|
list => $self, |
224
|
|
|
|
|
|
|
queue => $queue, |
225
|
|
|
|
|
|
|
rank => 0, |
226
|
|
|
|
|
|
|
personal => 0, |
227
|
|
|
|
|
|
|
}); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# and reorder all of them |
231
|
7
|
|
|
|
|
78284
|
for ($self->plugins($queue)) { |
232
|
15
|
|
|
|
|
281349
|
$_->rank( $new_rank{ $_->name }{rank} ); |
233
|
15
|
|
|
|
|
39271
|
$_->personal( $new_rank{ $_->name }{personal} ); |
234
|
15
|
|
|
|
|
5605
|
$_->update; |
235
|
|
|
|
|
|
|
} |
236
|
7
|
|
|
|
|
129153
|
return 1; |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 ->alias [app name] |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns a string which is can be used as an alias to post to a |
243
|
|
|
|
|
|
|
list. If you pass in an app name then it will use that in the |
244
|
|
|
|
|
|
|
description as |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
created by |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
B I
|
249
|
|
|
|
|
|
|
the script calling the method. This may be broken.> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=cut |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub alias { |
254
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
255
|
0
|
|
0
|
|
|
|
my $app = shift || "Siesta"; |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
( my $path = $0 ) =~ s!^(.*[\\/]).*$!$1!; |
258
|
0
|
|
|
|
|
|
my $tequila = $path."tequila"; |
259
|
0
|
|
|
|
|
|
return Siesta->bake('list_alias', |
260
|
|
|
|
|
|
|
app => $app, |
261
|
|
|
|
|
|
|
list => $self, |
262
|
|
|
|
|
|
|
tequila => $path."tequila", |
263
|
|
|
|
|
|
|
); |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; |
268
|
|
|
|
|
|
|
|