aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311.pm
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-03-27 12:54:18 +0100
committerStruan Donald <struan@exo.org.uk>2012-03-27 12:54:18 +0100
commitc93cb823dafba47191f14fd7b31cf7b9d0cf37e0 (patch)
tree4a448d6f3907e2acc66b70723d1714ebe7058c56 /perllib/Open311.pm
parent1e0914a87c0b6d43f142e2005f4d322d1fd01023 (diff)
add some better success and fail things to open311 module
Diffstat (limited to 'perllib/Open311.pm')
-rw-r--r--perllib/Open311.pm16
1 files changed, 14 insertions, 2 deletions
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index 50c7abb54..e609fb086 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -17,6 +17,8 @@ has test_get_returns => ( is => 'rw' );
has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml', service_request_updates => 'update.xml', update => 'update.xml' } } );
has debug => ( is => 'ro', isa => 'Bool', default => 0 );
has debug_details => ( is => 'rw', 'isa' => 'Str', default => '' );
+has success => ( is => 'rw', 'isa' => 'Bool', default => 0 );
+has error => ( is => 'rw', 'isa' => 'Str', default => '' );
sub get_service_list {
my $self = shift;
@@ -213,10 +215,17 @@ sub _get {
my $content;
if ( $self->test_mode ) {
+ $self->success(1);
$content = $self->test_get_returns->{ $path };
$self->test_uri_used( $uri->as_string );
} else {
$content = get( $uri->as_string );
+ if ( $content == undef ) {
+ $self->success(0);
+ $self->error('Failed to fetch');
+ } else {
+ $self->success(1);
+ }
}
return $content;
@@ -250,14 +259,17 @@ sub _post {
}
if ( $res->is_success ) {
+ $self->success(1);
return $res->decoded_content;
} else {
- warn sprintf(
+ $self->success(0);
+ $self->error( sprintf(
"request failed: %s\nerror: %s\n%s",
$res->status_line,
$self->_process_error( $res->decoded_content ),
$self->debug_details
- );
+ ) );
+ warn $self->error;
return 0;
}
}