File Coverage

blib/lib/JSON/API/Error.pm
Criterion Covered Total %
statement 11 17 64.7
branch 0 2 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 16 27 59.2


line stmt bran cond sub pod time code
1             package JSON::API::Error;
2              
3             # ABSTRACT: JSON API-style error objects
4              
5 1     1   67528 use Moo;
  1         11203  
  1         4  
6 1     1   2625 use overload bool => sub {1}, '""' => \&to_string;
  1     0   1018  
  1         9  
  0         0  
7              
8 1     1   637 use Types::Standard qw/Str HashRef/;
  1         73467  
  1         10  
9              
10             our $VERSION = '0.01';
11              
12             has code => (is => 'ro', isa => Str);
13             has detail => (is => 'ro', isa => Str);
14             has id => (is => 'ro', isa => Str);
15             has links => (is => 'ro', isa => HashRef);
16             has meta => (is => 'ro', isa => HashRef);
17             has source => (is => 'ro', isa => HashRef);
18             has status => (is => 'ro', isa => Str);
19             has title => (is => 'ro', isa => Str);
20              
21             sub to_string {
22 1     1 0 11428 my $self = shift;
23 1         11 return sprintf "%s: %s", $self->{source}->{pointer}, $self->{title};
24             }
25              
26             sub TO_JSON {
27 0     0 1   my $self = shift;
28 0           my $json = {};
29 0           for (qw/code detail id links meta source status title/) {
30 0 0         $json->{$_} = $self->$_ if $self->$_;
31             }
32 0           return $json;
33             }
34              
35             1;
36              
37             __END__