| 1 |
# Copyright (C) 2005, 2006 Software Freedom Law Center, Inc. |
|---|
| 2 |
# Author: Bradley M. Kuhn <bkuhn@softwarefreedom.org> |
|---|
| 3 |
# |
|---|
| 4 |
# This software gives you freedom; it is licensed to you under version |
|---|
| 5 |
# 3 of the GNU Affero General Public License. |
|---|
| 6 |
# |
|---|
| 7 |
# This software is distributed WITHOUT ANY WARRANTY, without even the |
|---|
| 8 |
# implied warranties of MERCHANTABILITY and FITNESS FOR A PARTICULAR |
|---|
| 9 |
# PURPOSE. See the GNU Affero General Public License for further |
|---|
| 10 |
# details. |
|---|
| 11 |
# |
|---|
| 12 |
# You should have received a copy of the GNU Affero General Public |
|---|
| 13 |
# License, version 3 along with this software. If not, see |
|---|
| 14 |
# <http://www.gnu.org/licenses/>. |
|---|
| 15 |
package SFLC::TimeTracker::Question::YesNoCat; |
|---|
| 16 |
|
|---|
| 17 |
use strict; |
|---|
| 18 |
use warnings; |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
require Exporter; |
|---|
| 22 |
#use AutoLoader qw(AUTOLOAD); |
|---|
| 23 |
|
|---|
| 24 |
use base qw(SFLC::TimeTracker::Question Exporter); |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
our @EXPORT_OK = (); |
|---|
| 28 |
|
|---|
| 29 |
our @EXPORT = qw( ); |
|---|
| 30 |
|
|---|
| 31 |
our $VERSION = '0.01'; |
|---|
| 32 |
|
|---|
| 33 |
use Carp; |
|---|
| 34 |
|
|---|
| 35 |
our $YES_RE = '(?:y+e*s*|t+r?u?e?)'; |
|---|
| 36 |
our $NO_RE = '(?:n+o*|f+a?l?s?e?)'; |
|---|
| 37 |
our $ABORT_RE = '(?:x|ab?o?r?t?|q)'; |
|---|
| 38 |
|
|---|
| 39 |
sub new { |
|---|
| 40 |
my $class = shift; |
|---|
| 41 |
my %args = @_; |
|---|
| 42 |
|
|---|
| 43 |
$args{numberRegex} = 'NOT_IN_USE'; |
|---|
| 44 |
$args{answers} = [ 'y', 'n', 'a']; |
|---|
| 45 |
my $self = SFLC::TimeTracker::Question::new($class, %args); |
|---|
| 46 |
croak "category value required for YesNoCat question" |
|---|
| 47 |
unless defined $args{category}; |
|---|
| 48 |
$self->{categoryValue} = $args{category}; |
|---|
| 49 |
$self->{resolutionData} = {}; |
|---|
| 50 |
$self->{resolutionData}{answerType} = 'loopback'; |
|---|
| 51 |
return $self; |
|---|
| 52 |
} |
|---|
| 53 |
############################################################################### |
|---|
| 54 |
sub setResolutionData { |
|---|
| 55 |
my $self = shift; |
|---|
| 56 |
|
|---|
| 57 |
$self->{resolutionData} = shift; |
|---|
| 58 |
} |
|---|
| 59 |
############################################################################### |
|---|
| 60 |
sub getResolutionData { |
|---|
| 61 |
my $self = shift; |
|---|
| 62 |
return %{$self->{resolutionData}}; |
|---|
| 63 |
} |
|---|
| 64 |
############################################################################### |
|---|
| 65 |
sub validateAnswer ($$) { |
|---|
| 66 |
my($self, $answer) = @_; |
|---|
| 67 |
|
|---|
| 68 |
my $n = $self->{numberRegex}; |
|---|
| 69 |
return undef if not defined $self->{answers}; |
|---|
| 70 |
if ($answer =~ /^\s*$YES_RE/) { |
|---|
| 71 |
return "yes"; |
|---|
| 72 |
} elsif ($answer =~ /^\s*$NO_RE/) { |
|---|
| 73 |
return "no"; |
|---|
| 74 |
} elsif ($answer =~ /^\s*$ABORT_RE/) { |
|---|
| 75 |
return "abort"; |
|---|
| 76 |
} else { |
|---|
| 77 |
return undef; |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
############################################################################### |
|---|
| 81 |
sub formatQuestion ($) { |
|---|
| 82 |
my($self) = @_; |
|---|
| 83 |
my $string = ""; |
|---|
| 84 |
|
|---|
| 85 |
return "$self->{question} (y|n|a)?"; |
|---|
| 86 |
} |
|---|
| 87 |
############################################################################### |
|---|
| 88 |
sub resolve ($$) { |
|---|
| 89 |
my($self, $answer) = @_; |
|---|
| 90 |
|
|---|
| 91 |
my $retVal = undef; |
|---|
| 92 |
|
|---|
| 93 |
$answer = $self->validateAnswer($answer); |
|---|
| 94 |
return "INVALID" unless defined $answer; |
|---|
| 95 |
my $categoryID; |
|---|
| 96 |
my $rejected = 0; |
|---|
| 97 |
if ($answer eq "yes") { |
|---|
| 98 |
$self->setResolutionData({ answerType => 'yes', |
|---|
| 99 |
category => $self->{categoryValue} }); |
|---|
| 100 |
# ( (defined $self->{resolutionData}{category}) |
|---|
| 101 |
# ? $self->{resolutionData}{category} : "/") |
|---|
| 102 |
# . $self->{categoryValue} }); |
|---|
| 103 |
return 'RESOLVED'; |
|---|
| 104 |
} elsif ($answer eq "no") { |
|---|
| 105 |
$self->setResolutionData({ answerType => 'no', category => undef}); |
|---|
| 106 |
#, |
|---|
| 107 |
# category => |
|---|
| 108 |
# ( (defined $self->{resolutionData}{category}) |
|---|
| 109 |
# ? $self->{resolutionData}{category} : "") }); |
|---|
| 110 |
return 'RESOLVED'; |
|---|
| 111 |
} elsif ($answer eq "abort") { |
|---|
| 112 |
$self->setResolutionData({ answerType => 'abort', category => undef}); |
|---|
| 113 |
return "REJECTED"; |
|---|
| 114 |
} else { |
|---|
| 115 |
$self->setResolutionData({ answerType => 'loopback', |
|---|
| 116 |
category => |
|---|
| 117 |
( (defined $self->{resolutionData}{category}) |
|---|
| 118 |
? $self->{resolutionData}{category} : "") }); |
|---|
| 119 |
return "INVALID"; |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
############################################################################### |
|---|
| 123 |
|
|---|
| 124 |
sub formatResolveString ($$) { |
|---|
| 125 |
my($self, $string) = @_; |
|---|
| 126 |
return "Aborted." if $string eq "REJECTED"; |
|---|
| 127 |
return "Your response was invalid." if $string =~ /^INVALID/; |
|---|
| 128 |
return "Ok." if $string =~ /^RESOLVED/; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
1; |
|---|
| 132 |
__END__ |
|---|
| 133 |
|
|---|
| 134 |
# |
|---|
| 135 |
# Local variables: |
|---|
| 136 |
# compile-command: "perl -I ../../../../Modules -c YesNoCat.pm" |
|---|
| 137 |
# End: |
|---|