From owner-svn-src-user@FreeBSD.ORG Thu Apr 17 11:48:35 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 55928862; Thu, 17 Apr 2014 11:48:35 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 29AA910BE; Thu, 17 Apr 2014 11:48:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3HBmZI7010826; Thu, 17 Apr 2014 11:48:35 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3HBmYDe010824; Thu, 17 Apr 2014 11:48:34 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201404171148.s3HBmYDe010824@svn.freebsd.org> From: Dag-Erling Smørgrav Date: Thu, 17 Apr 2014 11:48:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r264591 - user/des/fbp/lib/FBP/Schema/Result X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Apr 2014 11:48:35 -0000 Author: des Date: Thu Apr 17 11:48:34 2014 New Revision: 264591 URL: http://svnweb.freebsd.org/changeset/base/264591 Log: Add accessors for indirect relationships. Modified: user/des/fbp/lib/FBP/Schema/Result/Poll.pm user/des/fbp/lib/FBP/Schema/Result/Vote.pm Modified: user/des/fbp/lib/FBP/Schema/Result/Poll.pm ============================================================================== --- user/des/fbp/lib/FBP/Schema/Result/Poll.pm Thu Apr 17 10:53:10 2014 (r264590) +++ user/des/fbp/lib/FBP/Schema/Result/Poll.pm Thu Apr 17 11:48:34 2014 (r264591) @@ -181,6 +181,31 @@ sub active($;$) { DateTime->compare($when, $self->ends) <= 0; } +=head2 votes + +Return votes cast in this poll. In list context, returns a list of +votes. In scalar context, returns a resultset. + +=cut + +sub votes($) { + my ($self) = @_; + + return wantarray() ? $self->votes_rs->all : $self->votes_rs; +} + +=head2 votes_rs + +Return votes cast in this poll as a resultset. + +=cut + +sub votes_rs($) { + my ($self) = @_; + + return $self->questions->search_related_rs('votes'); +} + =head2 validate_answer Validates an answer to this poll and dies if it is not valid. @@ -207,6 +232,12 @@ sub validate_answer($%) { } } +=head2 commit_answer + +Commits an answer to this poll. + +=cut + sub commit_answer($$%) { my ($self, $voter, %answers) = @_; Modified: user/des/fbp/lib/FBP/Schema/Result/Vote.pm ============================================================================== --- user/des/fbp/lib/FBP/Schema/Result/Vote.pm Thu Apr 17 10:53:10 2014 (r264590) +++ user/des/fbp/lib/FBP/Schema/Result/Vote.pm Thu Apr 17 11:48:34 2014 (r264591) @@ -160,6 +160,18 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-04-16 20:57:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TIV5w+lodXu0vgk/zqosbA +=head2 poll + +Returns the poll in which this vote was cast. + +=cut + +sub poll($) { + my ($self) = @_; + + return $self->question->poll; +} + =head1 AUTHOR Dag-Erling Smørgrav