/[notice-sender]/trunk/Nos.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/Nos.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 29 by dpavlin, Mon May 16 20:58:44 2005 UTC revision 30 by dpavlin, Mon May 16 21:54:41 2005 UTC
# Line 76  sub new { Line 76  sub new {
76          $self ? return $self : return undef;          $self ? return $self : return undef;
77  }  }
78    
79    
80  =head2 add_member_to_list  =head2 add_member_to_list
81    
82  Add new member to list  Add new member to list
# Line 97  sub add_member_to_list { Line 98  sub add_member_to_list {
98    
99          my $arg = {@_};          my $arg = {@_};
100    
101          my $email = $arg->{'email'} || confess "can't add user without e-mail";          my $email = $arg->{'email'} || croak "can't add user without e-mail";
102          my $name = $arg->{'name'} || '';          my $name = $arg->{'name'} || '';
103          confess "need list name" unless ($arg->{'list'});          my $list_name = $arg->{'list'} || croak "need list name";
104    
105            my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";
106    
107          if (! Email::Valid->address($email)) {          if (! Email::Valid->address($email)) {
108                  carp "SKIPPING $name <$email>\n" if ($self->{'verbose'});                  carp "SKIPPING $name <$email>\n" if ($self->{'verbose'});
# Line 108  sub add_member_to_list { Line 111  sub add_member_to_list {
111    
112          carp "# $name <$email>\n" if ($self->{'verbose'});          carp "# $name <$email>\n" if ($self->{'verbose'});
113    
         my $lists = $self->{'loader'}->find_class('lists');  
114          my $users = $self->{'loader'}->find_class('users');          my $users = $self->{'loader'}->find_class('users');
115          my $user_list = $self->{'loader'}->find_class('user_list');          my $user_list = $self->{'loader'}->find_class('user_list');
116    
         my $list = $lists->find_or_create({  
                 name => $arg->{'list'},  
         }) || croak "can't add list ",$arg->{'list'},"\n";  
           
117          my $this_user = $users->find_or_create({          my $this_user = $users->find_or_create({
118                  email => $email,                  email => $email,
119                  full_name => $name,                  full_name => $name,
# Line 286  sub inbox_message { Line 284  sub inbox_message {
284  }  }
285    
286    
287    =head1 INTERNAL METHODS
288    
289    Beware of dragons! You shouldn't need to call those methods directly.
290    
291    =head2 _add_list
292    
293    Create new list
294    
295     my $list_obj = $nos->_add_list(
296            list => 'My list',
297            email => 'my-list@example.com',
298     );
299    
300    Returns C<Class::DBI> object for created list.
301    
302    =cut
303    
304    sub _add_list {
305            my $self = shift;
306    
307            my $arg = {@_};
308    
309            my $name = $arg->{'list'} || confess "can't add list without name";
310            my $email = $arg->{'email'} || confess "can't add list without e-mail";
311    
312            my $lists = $self->{'loader'}->find_class('lists');
313    
314            my $l = $lists->find_or_create({
315                    name => $name,
316                    email => $email,
317            });
318            
319            croak "can't add list $name\n" unless ($l);
320    
321            $l->dbi_commit;
322    
323            return $l;
324    
325    }
326    
327    
328    =head2 _get_list
329    
330    Get list C<Class::DBI> object.
331    
332     my $list_obj = $nos->check_list('My list');
333    
334    Returns false on failure.
335    
336    =cut
337    
338    sub _get_list {
339            my $self = shift;
340    
341            my $name = shift || return;
342    
343            my $lists = $self->{'loader'}->find_class('lists');
344    
345            return $lists->search({ name => $name });
346    }
347    
348    
349  =head1 EXPORT  =head1 EXPORT
350    
351  Nothing.  Nothing.

Legend:
Removed from v.29  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26