--- trunk/Nos.pm 2006/12/19 10:32:18 92 +++ trunk/Nos.pm 2006/12/19 15:04:05 93 @@ -16,7 +16,7 @@ our @EXPORT = qw( ); -our $VERSION = '0.8'; +our $VERSION = '0.9'; use Class::DBI::Loader; use Email::Valid; @@ -463,6 +463,7 @@ list => 'My list', driver => 'smtp', sleep => 3, + verbose => 1, ); Second option is driver which will be used for e-mail delivery. If not @@ -476,6 +477,10 @@ Send e-mail using SMTP server at 127.0.0.1 +=item verbose + +Display diagnostic output to C and C. + =back Any other driver name will try to use C module. @@ -494,6 +499,7 @@ my $list_name = lc($arg->{'list'}) || ''; my $driver = $arg->{'driver'} || ''; my $sleep = $arg->{'sleep'}; + my $verbose = $arg->{verbose}; $sleep ||= 3 unless defined($sleep); # number of messages sent o.k. @@ -508,7 +514,7 @@ } elsif ($driver && $driver ne '') { $email_send_driver = 'Email::Send::' . $driver; } else { - warn "dumping all messages to STDERR\n"; + warn "dumping all messages to STDERR\n" if ($verbose); } my $lists = $self->{'loader'}->find_class('lists'); @@ -529,7 +535,7 @@ while (my $m = $my_q->next) { next if ($m->all_sent); - print "sending message ",$m->message_id," enqueued on ",$m->date," to list ",$m->list_id->name,"\n"; + print "sending message ",$m->message_id," enqueued on ",$m->date," to list ",$m->list_id->name,"\n" if ($verbose); my $msg = $m->message_id->message; foreach my $u ($user_list->search(list_id => $m->list_id)) { @@ -539,9 +545,9 @@ my ($from,$domain) = split(/@/, $u->list_id->email, 2); if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) { - print "SKIP $to_email message allready sent\n"; + print "SKIP $to_email message allready sent\n" if ($verbose); } else { - print "=> $to_email "; + print "=> $to_email " if ($verbose); my $secret = $m->list_id->name . " " . $u->user_id->email . " " . $m->message_id; my $auth = Email::Auth::AddressHash->new( $secret, $self->{'hash_len'} ); @@ -589,15 +595,15 @@ }); $sent->dbi_commit; - print " - $sent_status\n"; + print " - $sent_status\n" if ($verbose); $ok++; } else { - warn "ERROR: $sent_status\n"; + warn "ERROR: $sent_status\n" if ($verbose); } if ($sleep) { - warn "sleeping $sleep seconds\n"; + warn "sleeping $sleep seconds\n" if ($verbose); sleep($sleep); } } @@ -1233,28 +1239,48 @@ } } -### +=head2 SendTest -=head1 NOTE ON ARRAYS IN SOAP +Internal function which does e-mail sending using C driver. -Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It -seems that SOAP::Lite client thinks that it has array with one element which -is array of hashes with data. + my $sent = SendTest( list => 'My list' ); -=head1 PRIVATE METHODS +Returns number of messages sent -Documented here because tests use them +=cut -=head2 _nos_object +sub SendTest { + my $self = shift; + my $args = shift; + die "list name required" unless ($args->{list}); - my $nos = $nos->_nos_object; + require Email::Send::Test; -=cut + my $nr_sent = $nos->send_queued_messages( + list => $args->{list}, + driver => 'Test', + sleep => 0, + verbose => 0, + ); -sub _nos_object { - return $nos; + my @emails = Email::Send::Test->emails; + + open(my $tmp, ">/tmp/soap-debug"); + use Data::Dump qw/dump/; + print $tmp "sent $nr_sent emails\n", dump(@emails); + close($tmp); + + return $nr_sent; } +### + +=head1 NOTE ON ARRAYS IN SOAP + +Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It +seems that SOAP::Lite client thinks that it has array with one element which +is array of hashes with data. + =head1 EXPORT Nothing.