From 8bfee41e214b015fe6eb8ef0c185859f5b6401a7 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 14 Aug 2010 05:18:31 +0200 Subject: Add remaining error classes, sort of --- lib/WWW/Efa/Error/Ambiguous.pm | 69 ++++++++++++++++++++++++++++++++++++++++++ lib/WWW/Efa/Error/Backend.pm | 64 +++++++++++++++++++++++---------------- lib/WWW/Efa/Error/NoData.pm | 50 ++++++++++++++++++++++++++++++ lib/WWW/Efa/Error/Setup.pm | 1 - 4 files changed, 157 insertions(+), 27 deletions(-) create mode 100644 lib/WWW/Efa/Error/Ambiguous.pm create mode 100644 lib/WWW/Efa/Error/NoData.pm (limited to 'lib/WWW/Efa/Error') diff --git a/lib/WWW/Efa/Error/Ambiguous.pm b/lib/WWW/Efa/Error/Ambiguous.pm new file mode 100644 index 0000000..e738a63 --- /dev/null +++ b/lib/WWW/Efa/Error/Ambiguous.pm @@ -0,0 +1,69 @@ +package WWW::Efa::Error::Ambiguous; + +=head1 NAME + +WWW::Efa::Error::Ambiguous - WWW::Efa error, ambiguous to/from/via input + +=head1 SYNOPSIS + + use WWW::Efa::Error::Ambiguous; + + my $error = WWW::Efa::Error::Ambiguous->new( + 'name_origin', 'Bredeney', 'Bredeney Friedhof' + ); + + die $error->as_string(); + # WWW::Efa error: ambiguous input for name_origin: + # Bredeney + # Bredeney Friedhof + +=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{}; +our @ISA = ('WWW::Efa::Error'); + +sub new { + my ($obj, $key, @possible) = @_; + my $ref = {}; + + $ref->{'key'} = $key; + $ref->{'possible'} = \@possible; + + 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) = @_; + + my $ret = sprintf( + "WWW::Efa error: ambiguous input for %s:\n", + $self->{'key'}, + ); + + foreach my $value (@{$self->{'possible'}}) { + $ret .= "\t$value\n"; + } + + return $ret; +} + +1; diff --git a/lib/WWW/Efa/Error/Backend.pm b/lib/WWW/Efa/Error/Backend.pm index b6ffa75..930fed5 100644 --- a/lib/WWW/Efa/Error/Backend.pm +++ b/lib/WWW/Efa/Error/Backend.pm @@ -1,5 +1,27 @@ package WWW::Efa::Error::Backend; +=head1 NAME + +WWW::Efa::Error::Backend - WWW::Efa unknown error from efa.vrr.de + +=head1 SYNOPSIS + + use WWW::Efa::Error::Backend; + + my $error = WWW::Efa::Error::Backend->new( + 'Yadda Yadda' + ); + + die $error->as_string(); + # WWW::Efa error from efa.vrr.de: + # Yadda Yadda + +=head1 DESCRIPTION + +Received an unknown error from efa.vrr.de + +=cut + use strict; use warnings; use 5.010; @@ -7,42 +29,32 @@ use 5.010; use base 'Exporter'; our @EXPORT_OK = qw{}; +our @ISA = ('WWW::Efa::Error'); sub new { - my ($obj, $type, $data) = @_; + my ($obj, $msg) = @_; my $ref = {}; - $ref->{'type'} = $type; - $ref->{'data'} = $data; + $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) = @_; - my $ret; - - given ($self->{'type'}) { - when ('no data') { - $ret = "WWW::Efa: efa.vrr.de returned no data\n"; - } - when ('ambiguous') { - $ret = sprintf( - "WWW::Efa: efa.vrr.de: Ambiguous input for %s:\n", - shift(@{$self->{'data'}}), - ); - foreach my $possible (@{$self->{'data'}}) { - $ret .= "\t${possible}\n"; - } - } - when ('error') { - $ret = sprintf( - "WWW::Efa: efa.vrr.de error:\n%s\n", - $self->{'data'}, - ); - } - } - return $ret; + + return sprintf( + "WWW::Efa error from efa.vrr.de:\n%s\n", + $self->{'message'}, + ); } 1; diff --git a/lib/WWW/Efa/Error/NoData.pm b/lib/WWW/Efa/Error/NoData.pm new file mode 100644 index 0000000..e74d220 --- /dev/null +++ b/lib/WWW/Efa/Error/NoData.pm @@ -0,0 +1,50 @@ +package WWW::Efa::Error::NoData; + +=head1 NAME + +WWW::Efa::Error::NoData - WWW::Efa error, efa.vrr.de returned no data + +=head1 SYNOPSIS + + use WWW::Efa::Error::Setup; + + my $error = WWW::Efa::Error::NoData->new(); + + die $error->as_string(); + # WWW::Efa error: No data returned by efa.vrr.de + +=head1 DESCRIPTION + +efa.vrr.de returned no parsable data + +=cut + +use strict; +use warnings; +use 5.010; + +use base 'Exporter'; + +our @EXPORT_OK = qw{}; +our @ISA = ('WWW::Efa::Error'); + +sub new { + my ($obj) = @_; + my $ref = {}; + + 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 { + return "WWW::Efa error: No data returned by efa.vrr.de\n"; +} + +1; diff --git a/lib/WWW/Efa/Error/Setup.pm b/lib/WWW/Efa/Error/Setup.pm index 386613b..9840687 100644 --- a/lib/WWW/Efa/Error/Setup.pm +++ b/lib/WWW/Efa/Error/Setup.pm @@ -52,7 +52,6 @@ Return the error as string, can directly be displayed to the user sub as_string { my ($self) = @_; - my $ret; return sprintf( "WWW::Efa setup error: Wrong arg for option %s: %s\n%s\n", -- cgit v1.2.3