summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-01-31 18:50:40 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-01-31 18:50:40 +0100
commit3557cfb0c021747caf5a5d2cbb192ac60c0c97bd (patch)
tree71474aee7e39eeb0d6f0d51cde65c241ddfb5efb
parent5dc6d0789474de48cf38650cae648c2367477cf7 (diff)
Improve(?) error handling
-rwxr-xr-xbin/efa10
-rw-r--r--lib/WWW/Efa.pm25
2 files changed, 17 insertions, 18 deletions
diff --git a/bin/efa b/bin/efa
index 1206f2c..4e4333b 100755
--- a/bin/efa
+++ b/bin/efa
@@ -97,8 +97,8 @@ $efa = WWW::Efa->new(
max_interchanges => $opt->{'max-change'},
);
-if (my $err = $efa->setup_error()) {
- die $err->as_string();
+if ($efa->error()) {
+ die $efa->error()->as_string();
}
if ($opt->{'test-parse'}) {
@@ -111,11 +111,7 @@ else {
);
}
-my $err = $efa->parse();
-
-if ($err and $err->isa('WWW::Efa::Error')) {
- die $err->as_string();
-}
+$efa->parse or die $efa->error()->as_string();
my @connections = $efa->connections();
diff --git a/lib/WWW/Efa.pm b/lib/WWW/Efa.pm
index 39e8d7c..b59bf53 100644
--- a/lib/WWW/Efa.pm
+++ b/lib/WWW/Efa.pm
@@ -477,6 +477,9 @@ If true: Prefer connections allowing to take a bike along
=back
+When encountering invalid hash keys, a WWW::Efa::Error object is stored to be
+retrieved by $efa->error();
+
=cut
sub new {
@@ -495,15 +498,15 @@ sub new {
return bless($ref, $obj);
}
-=head2 $efa->setup_error()
+=head2 $efa->error()
-In case WWW::Efa->new() encountered an error (usually invalid options), this
-returns a B<WWW::Efa::Error::Setup> object describing the exact error.
-Otherwise, returns nothing.
+In case a WWW::Efa operation encountered an error, this returns a
+B<WWW::Efa::Error> object related to the exact error. Otherwise, returns
+undef.
=cut
-sub setup_error {
+sub error {
my ($self) = @_;
if ($self->{'error'}) {
@@ -543,7 +546,8 @@ sub submit {
=head2 $efa->parse()
Parse the B<efa.vrr.de> reply.
-Returns undef on success and a WWW::Efa::Error object upon failure.
+returns a true value on success. Upon failure, returns undef and sets
+$efa->error() to a WWW::Efa::Error object.
=cut
@@ -568,17 +572,16 @@ sub parse {
if ($err = $self->check_ambiguous()) {
$self->{'error'} = $err;
- return $err;
}
elsif ($err = $self->check_no_connections()) {
$self->{'error'} = $err;
- return $err;
}
- elsif ($self->{'error'}) {
- return $self->{'error'};
+
+ if ($self->{'error'}) {
+ return;
}
- return $self->{'error'};
+ return 1;
}
sub check_ambiguous {