From owner-svn-src-user@FreeBSD.ORG Wed Apr 16 22:18:44 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 0DB27AC1; Wed, 16 Apr 2014 22:18:44 +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 D57271840; Wed, 16 Apr 2014 22:18:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3GMIhl6067907; Wed, 16 Apr 2014 22:18:43 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3GMIhUp067906; Wed, 16 Apr 2014 22:18:43 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201404162218.s3GMIhUp067906@svn.freebsd.org> From: Dag-Erling Smørgrav Date: Wed, 16 Apr 2014 22:18:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r264570 - user/des/fbp/lib/FBP/Controller 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: Wed, 16 Apr 2014 22:18:44 -0000 Author: des Date: Wed Apr 16 22:18:43 2014 New Revision: 264570 URL: http://svnweb.freebsd.org/changeset/base/264570 Log: Fix the question validation logic, which was broken by Perl's insistence on localizing loop variables. Modified: user/des/fbp/lib/FBP/Controller/Poll.pm Modified: user/des/fbp/lib/FBP/Controller/Poll.pm ============================================================================== --- user/des/fbp/lib/FBP/Controller/Poll.pm Wed Apr 16 22:04:09 2014 (r264569) +++ user/des/fbp/lib/FBP/Controller/Poll.pm Wed Apr 16 22:18:43 2014 (r264570) @@ -57,8 +57,9 @@ sub see :Chained('poll') :PathPart('') : my ($self, $c) = @_; my $poll = $c->stash->{poll}; - $c->stash(questions => $poll->questions-> - search_rs(undef, { order_by => { -asc => 'rank' } })); + my $questions = $poll->questions-> + search(undef, { order_by => { -asc => 'rank' } }); + $c->stash(questions => $questions); } =head2 vote @@ -73,7 +74,8 @@ sub vote :Chained('poll') :Path :Args(0) # Retrieve the poll and its list of questions my $poll = $c->stash->{poll}; my $pid = $poll->id; - my $questions = $poll->questions; + my $questions = $poll->questions-> + search(undef, { order_by => { -asc => 'rank' } }); $c->detach('/default') unless $poll && $questions; my $psession = $c->session->{$pid}; @@ -110,24 +112,23 @@ sub vote :Chained('poll') :Path :Args(0) # Ignore the buttons - stay on the same question } elsif ($c->req->params->{done}) { # Validate all the answers - for ($question = $questions->first; - $question && !$$psession{vote_error}; - $question = $questions->next) { + foreach $question ($questions->all) { try { my $answer = $answers->{$question->id}; $question->validate_answer(@{$answer // []}); } catch { + # This question was not answered correctly. Jump to + # it and display the corresponding error message. $$psession{vote_error} = $_; + $$psession{qid} = $question->id; + $c->response->redirect($c->request->uri); + $c->detach(); }; } - # If an error was found, $question now refers to the first - # question which was not answered correctly, and we will jump - # to that question and display an error message. If not, the - # voter has answered all the questions. - if (!$$psession{vote_error}) { - $c->response->redirect($c->uri_for('/poll', $pid, 'review')); - $c->detach(); - } + # All questions were answered correctly. Continue to the + # review page. + $c->response->redirect($c->uri_for('/poll', $pid, 'review')); + $c->detach(); } elsif ($c->req->params->{prev} && $question->prev) { $question = $question->prev; } elsif ($c->req->params->{next} && $question->next) {