summaryrefslogtreecommitdiff
path: root/lib/WWW/Efa/Error/Setup.pm
blob: 98406879c4528389d41c91a0d638b2f93651dabb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package WWW::Efa::Error::Setup;

=head1 NAME

WWW::Efa::Error::Setup - WWW::Efa error, happened in ->new()

=head1 SYNOPSIS

    use WWW::Efa::Error::Setup;

    my $error = WWW::Efa::Error::Setup->new(
        'max_interchanges', '-1', 'Must be positive'
    );

    die $error->as_string();
    # WWW::Efa setup error: Wrong arg for option max_interchanges: -1
    # Must be positive

=head1 DESCRIPTION

Class for all WWW::Efa-internal errors occuring during initialization. Usually
caused by missing or invalid setup arguments.

=cut

use strict;
use warnings;
use 5.010;

use base 'Exporter';

our @EXPORT_OK = qw{};

sub new {
	my ($obj, $key, $value, $msg) = @_;
	my $ref = {};

	$ref->{'key'}     = $key;
	$ref->{'value'}   = $value;
	$ref->{'message'} = $msg;

	return bless($ref, $obj);
}

=head1 METHODS

=head2 $error->as_string()

Return the error as string, can directly be displayed to the user

=cut

sub as_string {
	my ($self) = @_;

	return sprintf(
		"WWW::Efa setup error: Wrong arg for option %s: %s\n%s\n",
		@{$self}{'key', 'value', 'message'},
	);
}

=head2 $error->option()

Returns the option which caused the error.

=head2 $error->value()

Returns the value which caused the error.

=head2 $error->message()

Returns a message describing what went wrong and how to fix it.

=cut

sub option  { return $_[0]->{'key'}     }
sub value   { return $_[0]->{'value'}   }
sub message { return $_[0]->{'message'} }

1;