[patch] YAPC::Talk - make more use of Class::DBI

[prev] [thread] [next] [lurker] [Date index for 2003/11/24]

From: Richard Clamp
Subject: [patch] YAPC::Talk - make more use of Class::DBI
Date: 14:15 on 24 Nov 2003
--wac7ysb48OaltWcw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I just took a quick stroll through the code and noticed the
Talk->get_user_id method seemed superflous.

The attached patch refactors this a little by setting up a has_a
relationship between Talk and Person, and then discarding the method.

All tests continue to pass.

ps.  Could you add the ListHeaders plugin to the list config, as
filtering on subject line feels wrong.

-- 
Richard Clamp <richardc@xxxxxxxxx.xxx>

--wac7ysb48OaltWcw
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="yapcom.talk_person"

Index: lib/YAPC/Talk.pm
===================================================================
--- lib/YAPC/Talk.pm	(revision 13)
+++ lib/YAPC/Talk.pm	(working copy)
@@ -6,6 +6,7 @@
 use base 'YAPC::DBI';
 use YAPC::Config;
 __PACKAGE__->set_up_table('talks');
+__PACKAGE__->has_a(user_id => 'YAPC::Person');
 
 =head2 propose
 
@@ -45,24 +46,6 @@
     __PACKAGE__->create(\%args);
 }
 
-=head2 get_user_id
-
-Returns the user id of the Person who submitted the talk
-Arguments:  (id => 'the id of the talk')
-
-=cut
-sub get_user_id {
-   my $self = shift;
-   my %args = @_;   # id => ...
-
-   return undef if not $args{id};
-
-   my @talks;
-   @talks= __PACKAGE__->search(%args);
-   return undef if @talks != 1;
-
-   return $talks[0]->user_id;
-} 
 
 =head2 VERSION
 
Index: lib/YAPC/Organizer.pm
===================================================================
--- lib/YAPC/Organizer.pm	(revision 13)
+++ lib/YAPC/Organizer.pm	(working copy)
@@ -476,8 +476,7 @@
 
        return $t->output;
     } else {
-       my $talker_id = YAPC::Talk->get_user_id(id => $talk->id);
-       my $person = YAPC::Person->retrieve($talker_id);
+       my $person = $talk->user_id;
        my $text = "Subject: " . $talk->title . "\n";
        $text .= "Speaker: ". $person->fname . "  " . $person->lname . "  " . $person->email . "\n";
        $text .= "Language: " . $talk->language . "\n";

--wac7ysb48OaltWcw--

Generated at 17:06 on 24 Nov 2003 by mariachi 0.51