[prev] [thread] [next] [lurker] [Date index for 2002/08/26]
Update of /cvsroot/siesta/siesta/lib/Siesta In directory usw-pr-cvs1:/tmp/cvs-serv2211/lib/Siesta Modified Files: List.pm Added Files: Storage.pm Log Message: refactor into Storage::DBI Index: List.pm =================================================================== RCS file: /cvsroot/siesta/siesta/lib/Siesta/List.pm,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- List.pm 26 Aug 2002 16:42:54 -0000 1.18 +++ List.pm 26 Aug 2002 21:47:04 -0000 1.19 @@ -1,3 +1,4 @@ +# $Id$ =pod =head1 NAME @@ -18,9 +19,8 @@ use Class::MethodMaker get_set => [ qw( id owner post_address return_path created ) ]; use Siesta::User; -use Siesta::Storage::Table::Lists; -use Siesta::Storage::Table::List_Users; -use Siesta::Storage::Table::List_Plugins; +use Siesta::Storage::DBI; +my $storage = Siesta::Storage::DBI->new(); =head2 new(id) @@ -30,20 +30,12 @@ sub new { my $class = shift; - my $id = shift; - - my $t_lists = Siesta::Storage::Table::Lists->new(); - my @results = $t_lists->search(id => $id); - if (!(scalar(@results) == 1)) { - # we need to decide error handling in libs ;-) - return undef; - } + my $id = shift; - if (exists($results[0]->{__Changed})) { - delete($results[0]->{__Changed}); - } + my %list = $storage->load_list( $id ); + return unless %list; - return bless $results[0], $class; + return bless \%list, $class; } =head2 is_member(member) @@ -58,9 +50,7 @@ my $self = shift; my $member = shift; my $address = ref($member) ? $member->id() : $member; - my $t_list_users = Siesta::Storage::Table::List_Users->new(); - my @results = $t_list_users->search2(list_id => $self->{id}, user_id => $address); - return scalar(@results); + $storage->member_of_list( $self->id, $address ); } =head2 ->add_member( $member ) @@ -76,13 +66,7 @@ return if $self->is_member($member); - # this is hacky, but I'm too lazy to learn Class::DBI today -- richardc - my $table = Siesta::Storage::Table::List_Users->new(); - my $id = $self->id; - $table->dbh->do(qq{INSERT INTO list_users (list_id, user_id) - VALUES ('$id', '$address')}) - or die $table->dbh->errstr; - return 1; + $storage->add_member_to_list( $self->id, $address ); } =head2 ->remove_member( $member ) @@ -93,15 +77,11 @@ sub remove_member { my $self = shift; - my ($member) = @_; - if ($self->is_member($member) == 1) { - my $address = ref($member) ? $member->id() : $member; - my $t_list_users = Siesta::Storage::Table::List_Users->new(); - my @results = $t_list_users->search2(list_id => $self->{id}, user_id => $address); - # print scalar(@results),"\n"; - return $results[0]->delete(); - } - return; + my $member = shift; + my $address = ref($member) ? $member->id() : $member; + + return unless $self->is_member($member); + return $storage->remove_member_from_list( $self->id, $address ); } =head2 members() @@ -111,15 +91,14 @@ =cut sub members { - my $self = shift; - my $t_list_users = Siesta::Storage::Table::List_Users->new(); - my @results = $t_list_users->search(list_id => $self->{id}); + 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 ... - @results = map { Siesta::User->new($_->user_id()) } @results; - return @results; + # 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 { + new Siesta::User $_->user_id + } $storage->list_members( $self->id ); } =head2 plugins() @@ -130,12 +109,10 @@ sub plugins { my $self = shift; - my $t_list_plugins = Siesta::Storage::Table::List_Plugins->new(); - my @results = $t_list_plugins->search(list_id => $self->{id}); - return map { $_->plugin_id } @results; - # you could change this, so it returned the Plugin objects, - # this would make it consistent with members() + # you could change this, so it returned the Plugin objects, + # this would make it consistent with members() + $storage->list_plugins( $self->id ); } 1;
Generated at 13:57 on 01 Jul 2004 by mariachi 0.52