| 1 | # $Id: List.pm 1334 2003-08-13 13:07:42Z richardc $ | ||||||||||||||||||||||||||||
| 2 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Siesta::List; | ||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use UNIVERSAL::require; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 27 | ▶ | use Siesta::DBI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 27 | ▶ | use base 'Siesta::DBI'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 27 | ▶ | use POSIX qw( strftime ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 27 | __PACKAGE__->set_up_table('list'); | |||||||||||||||||||||||||||
| 10 | 27 | __PACKAGE__->load_alias('name'); | |||||||||||||||||||||||||||
| 11 | 27 | __PACKAGE__->has_a( owner => 'Siesta::Member' ); | |||||||||||||||||||||||||||
| 12 | 27 | __PACKAGE__->has_many( members => [ 'Siesta::Subscription' => 'member' ] ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # this is a bit funny, never mind | ||||||||||||||||||||||||||||
| 15 | 27 | __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 | 1 | ▶ | sub new { shift->create({ @_ }) } | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | 9 | ▶ | sub address { | ||||||||||||||||||||||||||
|
Subroutine
address: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 9 | my $pipeline = shift; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # XXX - hacky | ||||||||||||||||||||||||||||
| 52 | 9 | my $address = $self->post_address; | |||||||||||||||||||||||||||
| 53 | 9 | ▶ | return $address if !$pipeline || $pipeline eq 'post'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $pipeline or $pipeline eq "post"
MC/DC0%0/2
not $pipeline or $pipeline eq "post"
not $pipeline
$pipeline eq "post"
Truth table33%1/3
not(A) or B
A= not $pipelineB= $pipeline eq "post"
| |||||||||||||||||||||||||||||
| 54 | 9 | $address =~ s/\@/-$pipeline\@/; | |||||||||||||||||||||||||||
| 55 | 9 | 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 L<Siesta::Member>s 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 | 22 | ▶ | sub is_member { | ||||||||||||||||||||||||||
|
Subroutine
is_member: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | 22 | my $member = shift; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 22 | ▶ | $member = Siesta::Member->load( $member ) unless ref $member; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 22 | ▶ | return unless $member; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 19 | 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 | 8 | ▶ | sub add_member { | ||||||||||||||||||||||||||
|
Subroutine
add_member: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 8 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | 8 | my $member = shift; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 8 | ▶ | $member = Siesta::Member->find_or_create({ email => $member }) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | unless ref $member; | ||||||||||||||||||||||||||||
| 100 | 8 | ▶ | return if $self->is_member( $member ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 8 | 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 | 7 | ▶ | sub remove_member { | ||||||||||||||||||||||||||
|
Subroutine
remove_member: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 7 | my $self = shift; | |||||||||||||||||||||||||||
| 114 | 7 | my $member = shift; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 7 | ▶ | $member = Siesta::Member->load( $member ) unless ref $member; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 7 | ▶ | return unless $member; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 5 | my ($record) = Siesta::Subscription->search( member => $member, | |||||||||||||||||||||||||||
| 119 | list => $self ); | ||||||||||||||||||||||||||||
| 120 | 5 | ▶ | return unless $record; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 4 | $record->delete; | |||||||||||||||||||||||||||
| 122 | 4 | 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 | 0 | ▶ | sub queues { | ||||||||||||||||||||||||||
|
Subroutine
queues: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | 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 | 68 | ▶ | sub plugins { | ||||||||||||||||||||||||||
|
Subroutine
plugins: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 68 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 68 | ▶ | my $queue = shift || 'post'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 'post'
MC/DC100%1/1
shift() || 'post'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 150 | # map from the raw accessor we set up into the correct classes | ||||||||||||||||||||||||||||
| 151 | 68 | return map { $_->promote } grep { $_->queue eq $queue } $self->_plugins; | |||||||||||||||||||||||||||
| 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 | 17 | ▶ | sub add_plugin { | ||||||||||||||||||||||||||
|
Subroutine
add_plugin: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 166 | 17 | my $queue = shift; | |||||||||||||||||||||||||||
| 167 | 17 | my $plugin = shift; | |||||||||||||||||||||||||||
| 168 | 17 | my $pos = shift; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 17 | my $personal = ($plugin =~ s/^\+//); | |||||||||||||||||||||||||||
| 171 | 17 | my @existing = $self->plugins( $queue ); | |||||||||||||||||||||||||||
| 172 | croak "can only add 1 instance of a plugin to a queue" | ||||||||||||||||||||||||||||
| 173 | 17 | ▶ | if grep { $_->name eq $plugin } @existing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 17 | ▶ | if ( defined $pos && $existing[ $pos - 1 ] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $pos and $existing[$pos - 1]
MC/DC0%0/2
defined $pos and $existing[$pos - 1]
defined $pos
$existing[$pos - 1]
Truth table33%1/3
A and B
A= defined $posB= $existing[$pos - 1]
| |||||||||||||||||||||||||||||
| 176 | 1 | for (@existing) { # shuffle the others up | |||||||||||||||||||||||||||
| 177 | 2 | ▶ | if ($_->rank >= $pos) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 2 | $_->rank( $_->rank + 1 ); | |||||||||||||||||||||||||||
| 179 | 2 | $_->update; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | else { | ||||||||||||||||||||||||||||
| 184 | 16 | $pos = @existing + 1; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 17 | 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 | 12 | ▶ | sub set_plugins { | ||||||||||||||||||||||||||
|
Subroutine
set_plugins: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 204 | 12 | my $queue = shift; | |||||||||||||||||||||||||||
| 205 | 12 | my $i; | |||||||||||||||||||||||||||
| 206 | 12 | my %new_rank = map { (my $name = $_) =~ s/^\+//; | |||||||||||||||||||||||||||
| 207 | 24 | $name => { personal => $_ ne $name, | |||||||||||||||||||||||||||
| 208 | rank => ++$i } | ||||||||||||||||||||||||||||
| 209 | } @_; | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 12 | ▶ | die "'$queue' doesn't look like an queue id" unless $queue =~ /^[a-z]+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | # first, delete the plugins that don't exist in the new order | ||||||||||||||||||||||||||||
| 214 | 12 | for ($self->plugins($queue)) { | |||||||||||||||||||||||||||
| 215 | 16 | ▶ | $_->delete unless $new_rank{ $_->name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # then just add new ones | ||||||||||||||||||||||||||||
| 219 | 12 | my %old = map { $_->name => 1 } $self->plugins($queue); | |||||||||||||||||||||||||||
| 220 | 12 | for my $plugin (keys %new_rank) { | |||||||||||||||||||||||||||
| 221 | 24 | ▶ | next if $old{ $plugin }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 12 | 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 | 12 | for ($self->plugins($queue)) { | |||||||||||||||||||||||||||
| 232 | 24 | $_->rank( $new_rank{ $_->name }{rank} ); | |||||||||||||||||||||||||||
| 233 | 24 | $_->personal( $new_rank{ $_->name }{personal} ); | |||||||||||||||||||||||||||
| 234 | 24 | $_->update; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | 12 | 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 <app name> | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | B<NB> I<assumes that the path to 'tequila' is the same as the path of | ||||||||||||||||||||||||||||
| 249 | the script calling the method. This may be broken.> | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =cut | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 1 | ▶ | sub alias { | ||||||||||||||||||||||||||
|
Subroutine
alias: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 255 | 1 | ▶ | my $app = shift || "Siesta"; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'Siesta'
MC/DC0%0/1
shift() || 'Siesta'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 1 | ( my $path = $0 ) =~ s!^(.*[\\/]).*$!$1!; | |||||||||||||||||||||||||||
| 258 | 1 | my $tequila = $path."tequila"; | |||||||||||||||||||||||||||
| 259 | 1 | return Siesta->bake('list_alias', | |||||||||||||||||||||||||||
| 260 | app => $app, | ||||||||||||||||||||||||||||
| 261 | list => $self, | ||||||||||||||||||||||||||||
| 262 | tequila => $path."tequila", | ||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 27 | 1; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||