[prev] [thread] [next] [lurker] [Date index for 2003/03/15]
Update of /cvsroot/siesta/siesta/lib/Siesta In directory sc8-pr-cvs1:/tmp/cvs-serv10805/lib/Siesta Modified Files: List.pm Plugin.pm Storage.pm User.pm Log Message: A metric ton of changes. * All tables now have abstract id columns, so a users email address is now $user->email and a lists name is $list->name * Storage methods take ids, not objects * User/List methods try to be a bit less magical/vaired about what they take as parameters Since modules and tests have been changed at the same time I expect there to be many bugs, but those'll be squished RSN Index: List.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/List.pm,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- List.pm 12 Sep 2002 12:55:31 -0000 1.37 +++ List.pm 15 Mar 2003 20:15:41 -0000 1.38 @@ -6,7 +6,7 @@ use vars qw(@fields); BEGIN { - @fields = qw(id post_address return_path owner created ); + @fields = qw( id name post_address return_path owner created ); } use Class::MethodMaker get_set => \@fields; @@ -19,20 +19,30 @@ =head2 ->new -takes a list_id and retrieves the information from the database. +takes a list name and retrieves the information from the database. =cut sub new { my $class = shift; - my $id = shift; + my $name = shift; - my %list = Siesta->storage->load_list($id); + my %list = Siesta->storage->load_list($name); return unless %list; return bless \%list, $class; } + +sub new_from_id { + my $class = shift; + my $id = shift; + + my $name = Siesta->storage->list_name_from_id($id); + return unless $name; + $class->new( $name ); +} + =head2 ->new_from_hash( %hash ) takes a hash (possible keys are the values of @Siesta::List::fields) @@ -51,9 +61,13 @@ get and set the id (must be unique) +=head2 ->name + +the short name of the list + =head2 ->owner -get and set the owner (usually an email address) +get and set the owner (an email address) =head2 ->post_address @@ -61,7 +75,7 @@ =head2 ->return_path -the email address that bounces should come back to +the email address that bounces should come back to =head2 ->created @@ -75,7 +89,11 @@ sub save { my $self = shift; - return Siesta->storage->save_list($self); + my $res = Siesta->storage->save_list($self); + return unless $res; + # need to populate id + %$self = Siesta->storage->load_list( $self->name ); + return $res; } =head2 ->delete @@ -94,34 +112,35 @@ get and set config values for this User. -=head2 is_member(member) +=head2 is_member( $user ) Returns true or false depending if member is a member of this -list. This can take either a User object or an email address (the -primary key for users). +list. This can take either a User object or an email address. =cut sub is_member { - my $self = shift; - my $member = shift; - my $address = ref($member) ? $member->id() : $member; - Siesta->storage->member_of_list( $self->id, $address ); + my $self = shift; + my $user = shift; + + $user = Siesta::User->new_from_email( $user ) unless ref $user; + return unless $user; + Siesta->storage->member_of_list( $self->id, $user->id ); } -=head2 ->add_member( $member ) +=head2 ->add_member( $user ) Adds a member to a list =cut sub add_member { - my $self = shift; - my $member = shift; - my $address = ref $member ? $member->id : $member; + my $self = shift; + my $user = shift; - return if $self->is_member($member); - return Siesta->storage->add_member_to_list( $self->id, $address ); + $user = Siesta::User->new_from_email( $user ) unless ref $user; + return if $self->is_member( $user ); + return Siesta->storage->add_member_to_list( $self->id, $user->id ); } =head2 ->remove_member( $member ) @@ -131,12 +150,12 @@ =cut sub remove_member { - my $self = shift; - my $member = shift; - my $address = ref($member) ? $member->id() : $member; + my $self = shift; + my $user = shift; + $user = Siesta::User->new_from_email( $user ) unless ref $user; - return unless $self->is_member($member); - return Siesta->storage->remove_member_from_list( $self->id, $address ); + return unless $self->is_member($user); + return Siesta->storage->remove_member_from_list( $self->id, $user->id ); } =head2 ->members() @@ -148,11 +167,8 @@ sub members { my $self = shift; - # this is inefficient as new() is going to do another select - # i might change new() to accept an AoH and bless them after - # cleanup ... return - map { Siesta::User->new( $_->{user_id} ) } + map { Siesta::User->new( $_ ) } Siesta->storage->list_members( $self->id ); } @@ -172,15 +188,15 @@ =head2 ->add_plugin($plugin, [ $position ]) -Add a plugin to the end of the processing queue for this +Add a plugin to the end of the processing queue for this list. By supplying a position the plugin will be inserted there. -=cut +=cut sub add_plugin { my $self = shift; - return Siesta->storage->add_plugin_to_list( $self, @_ ); + return Siesta->storage->add_plugin_to_list( $self->id, @_ ); } @@ -191,10 +207,9 @@ =cut sub set_plugins { - my $self = shift; - return Siesta->storage->set_plugins( $self, @_ ); + return Siesta->storage->set_plugins( $self->id, @_ ); } 1; Index: Plugin.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/Plugin.pm,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- Plugin.pm 17 Oct 2002 12:57:29 -0000 1.29 +++ Plugin.pm 15 Mar 2003 20:15:42 -0000 1.30 @@ -43,8 +43,8 @@ ( my $package = ref $self ) =~ s!^.*::!!; - my $list_id = defined $mail->list ? $mail->list->id() : undef; - my $user_id = defined $mail->user ? $mail->user->id() : undef; + my $list_id = defined $mail->list ? $mail->list->id : undef; + my $user_id = defined $mail->user ? $mail->user->id : undef; return Siesta::Preferences::preference( $package, $user_id, $list_id, @_ ); } @@ -62,8 +62,8 @@ ( my $package = ref $self ) =~ s!^.*::!!; - my $list_id = defined $mail->list ? $mail->list->id() : undef; - my $user_id = defined $mail->user ? $mail->user->id() : undef; + my $list_id = defined $mail->list ? $mail->list->id : undef; + my $user_id = defined $mail->user ? $mail->user->id : undef; return Siesta::Preferences::delete( $package, $user_id, $list_id, @_ ); } Index: Storage.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/Storage.pm,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- Storage.pm 17 Oct 2002 12:57:29 -0000 1.21 +++ Storage.pm 15 Mar 2003 20:15:43 -0000 1.22 @@ -83,9 +83,9 @@ removes a user, returns true on success -=item ->list_members( $list ) +=item ->list_members( $list_id ) -returns a list of User objects; +returns a list of user ids =item ->list_plugins( $list ) @@ -94,8 +94,8 @@ =item ->add_plugin_to_list ($list, $plugin) =item ->add_plugin_to_list ($list, $plugin, $position) -Add a plugin to the processing order of the list. If you -pass a position then the plugin will inserted there (the +Add a plugin to the processing order of the list. If you +pass a position then the plugin will inserted there (the order is indexed from 1 i.e 1 is the first position in the list) Returns 1 on success or undef on failure. @@ -125,6 +125,6 @@ Delete the value of the preference '$key' for this tuple. -=cut +=cut 1; Index: User.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/User.pm,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- User.pm 14 Sep 2002 09:15:09 -0000 1.17 +++ User.pm 15 Mar 2003 20:15:44 -0000 1.18 @@ -7,7 +7,7 @@ # fuck the users, fuck them up their stupid asses BEGIN { - @fields = qw(id forename surname password bouncing lastbounce created); + @fields = qw(id email forename surname password bouncing lastbounce created); } use Class::MethodMaker get_set => \@fields; @@ -29,11 +29,20 @@ my $id = shift; my %user = Siesta->storage->load_user($id); + use Data::Dumper; + #die Dumper { id => $id, user => \%user }; return unless %user; return bless \%user, $class; } +sub new_from_email { + my $class = shift; + my $email = shift; + my $id = Siesta->storage->user_id_from_email( $email ); + $class->new($id); +} + =head2 ->new_from_hash( %hash ) takes a hash (possible keys are the values of @Siesta::User::fields) @@ -50,7 +59,11 @@ =head2 ->id -get and set their id (usually their email address) +get and set their id + +=head2 ->email + +get and set their email address =head2 ->forename @@ -68,7 +81,8 @@ sub lists { my $self = shift; - return Siesta->storage->user_lists( $self->id ); + return map { Siesta::List->new_from_id( $_ ) } + Siesta->storage->user_lists( $self->id ); } =head2 ->save @@ -79,7 +93,12 @@ sub save { my $self = shift; - return Siesta->storage->save_user($self); + my $res = Siesta->storage->save_user($self); + return unless $res; + # need to populate id + $self->id( Siesta->storage->user_id_from_email( $self->email ) ); + return $res; + } =head2 ->delete
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52