Skip to content
This repository
Browse code

use module::pluggable to get a list of avaible sending modules

skip on sending if the sending module isn't available
  • Loading branch information...
commit a16e71730cf86cd48773ffbd8390c65e1dc2fc6a 1 parent 05da714
Struan Donald authored April 03, 2012
10  perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -12,7 +12,7 @@ use mySociety::EmailUtil;
12 12
 use mySociety::MaPit;
13 13
 
14 14
 use FixMyStreet::App;
15  
-use FixMyStreet::SendReport::Email;
  15
+use FixMyStreet::SendReport;
16 16
 
17 17
 my $site_restriction;
18 18
 my $site_key;
@@ -231,6 +231,10 @@ sub send_reports {
231 231
         council => { '!=', undef },
232 232
     } );
233 233
     my (%notgot, %note);
  234
+
  235
+    my $s = FixMyStreet::SendReport->new();
  236
+    my $senders = $s->get_senders;
  237
+
234 238
     while (my $row = $unsent->next) {
235 239
 
236 240
         my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
@@ -312,6 +316,10 @@ sub send_reports {
312 316
                 push @dear, $name;
313 317
                 my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} );
314 318
                 $sender = "FixMyStreet::SendReport::$sender";
  319
+                if ( ! exists $senders->{ $sender } ) {
  320
+                    warn "No such sender [ $sender ] for council $name ( $council )";
  321
+                    next;
  322
+                }
315 323
                 $reporters{ $sender } = $sender->new() unless $reporters{$sender};
316 324
                 $reporters{ $sender }->add_council( $council, $name );
317 325
             }
13  perllib/FixMyStreet/SendReport.pm
@@ -2,9 +2,22 @@ package FixMyStreet::SendReport;
2 2
 
3 3
 use Moose;
4 4
 
  5
+use Module::Pluggable
  6
+    sub_name    => 'senders',
  7
+    search_path => __PACKAGE__,
  8
+    require     => 1;
  9
+
5 10
 has 'councils' => (is => 'rw', isa => 'HashRef', default => sub { {} } );
6 11
 has 'to' => (is => 'rw', isa => 'ArrayRef', default => sub { [] } );
7 12
 
  13
+sub get_senders {
  14
+    my $self = shift;
  15
+
  16
+    my %senders = map { $_ => 1 } $self->senders;
  17
+
  18
+    return \%senders;
  19
+}
  20
+
8 21
 sub reset {
9 22
     my $self = shift;
10 23
 

0 notes on commit a16e717

Please sign in to comment.
Something went wrong with that request. Please try again.