Annotation of loncom/homework/math_parser/CalcException.pm, revision 1.1
1.1 ! damieng 1: # The LearningOnline Network with CAPA - LON-CAPA
! 2: # Calculation exception
! 3: #
! 4: # Copyright (C) 2014 Michigan State University Board of Trustees
! 5: #
! 6: # This program is free software: you can redistribute it and/or modify
! 7: # it under the terms of the GNU General Public License as published by
! 8: # the Free Software Foundation, either version 3 of the License, or
! 9: # (at your option) any later version.
! 10: #
! 11: # This program is distributed in the hope that it will be useful,
! 12: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 13: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 14: # GNU General Public License for more details.
! 15: #
! 16: # You should have received a copy of the GNU General Public License
! 17: # along with this program. If not, see <http://www.gnu.org/licenses/>.
! 18: #
! 19:
! 20: ##
! 21: # Calculation exception
! 22: ##
! 23: package Apache::math_parser::CalcException;
! 24:
! 25: use strict;
! 26: use warnings;
! 27: use utf8;
! 28:
! 29: use Apache::lonlocal;
! 30:
! 31: use overload '""' => \&toString;
! 32:
! 33: ##
! 34: # Constructor
! 35: # @param {string} msg - error message, using [_1] for the first parameter
! 36: # @param {...string} param - parameters for the message
! 37: ##
! 38: sub new {
! 39: my $class = shift;
! 40: my $self = {
! 41: _msg => shift,
! 42: _params => [],
! 43: };
! 44: while (@_) {
! 45: push(@{$self->{_params}}, shift);
! 46: }
! 47: bless $self, $class;
! 48: return $self;
! 49: }
! 50:
! 51: # Attribute helpers
! 52:
! 53: ##
! 54: # Error message, using [_1] for the first parameter.
! 55: # @returns {string}
! 56: ##
! 57: sub msg {
! 58: my $self = shift;
! 59: return $self->{_msg};
! 60: }
! 61:
! 62: ##
! 63: # Parameters for the message.
! 64: # @returns {string[]}
! 65: ##
! 66: sub params {
! 67: my $self = shift;
! 68: return $self->{_params};
! 69: }
! 70:
! 71:
! 72: ##
! 73: # Returns the exception as a string, for debug only.
! 74: # @returns {string}
! 75: ##
! 76: sub toString {
! 77: my $self = shift;
! 78: my $s = "Calculation error: ".$self->msg;
! 79: if (scalar(@{$self->params}) > 0) {
! 80: $s .= ", ".join(", ", @{$self->params});
! 81: }
! 82: return $s;
! 83: }
! 84:
! 85: ##
! 86: # Returns the error message localized for the user interface.
! 87: # @returns {string}
! 88: ##
! 89: sub getLocalizedMessage {
! 90: my $self = shift;
! 91: return mt($self->msg, @{$self->params});
! 92: }
! 93:
! 94: 1;
! 95: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>