diff options
author | franck cuny <franck@lumberjaph.net> | 2010-02-18 15:34:56 +0100 |
---|---|---|
committer | franck cuny <franck@lumberjaph.net> | 2010-02-18 15:34:56 +0100 |
commit | 240651a912501d666b2fa8014f134e80798d0835 (patch) | |
tree | 8cbde046f34c96b75502e021c0b72b3b2a5507ac /lib/MooseX/Net/API/Error.pm | |
parent | Checking in changes prior to tagging of version 0.10. Changelog diff is: (diff) | |
download | moosex-net-api-240651a912501d666b2fa8014f134e80798d0835.tar.gz |
update build uri, move error to it's own package
Diffstat (limited to '')
-rw-r--r-- | lib/MooseX/Net/API/Error.pm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/MooseX/Net/API/Error.pm b/lib/MooseX/Net/API/Error.pm new file mode 100644 index 0000000..0542613 --- /dev/null +++ b/lib/MooseX/Net/API/Error.pm @@ -0,0 +1,33 @@ +package MooseX::Net::API::Error; + +use Moose; +use JSON::XS; +use Moose::Util::TypeConstraints; +use overload '""' => \&error; + +subtype error => as 'Str'; +coerce error => from 'HashRef' => via { encode_json $_}; + +has http_error => ( + is => 'ro', + isa => 'HTTP::Response', + handles => { http_message => 'message', http_code => 'code' } +); +has reason => ( + is => 'ro', + isa => 'error', + predicate => 'has_reason', + coerce => 1 +); + +sub error { + my $self = shift; + return + ( $self->has_reason && $self->reason ) + || ( $self->http_message . ": " . $self->http_code ) + || 'unknown'; +} + +1; + +__END__ |