File Coverage

blib/lib/Whelk/Schema/Definition/Boolean.pm
Criterion Covered Total %
statement 23 23 100.0
branch 10 10 100.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 42 42 100.0


line stmt bran cond sub pod time code
1             package Whelk::Schema::Definition::Boolean;
2             $Whelk::Schema::Definition::Boolean::VERSION = '1.04';
3 17     17   10352 use Whelk::StrictBase 'Whelk::Schema::Definition::_Scalar';
  17         37  
  17         124  
4 17     17   128 use JSON::PP;
  17         48  
  17         1472  
5 17     17   168 use List::Util qw(none);
  17         38  
  17         7498  
6              
7             sub openapi_dump
8             {
9 25     25 1 45 my ($self, $openapi_obj, %hints) = @_;
10              
11 25         96 my $res = $self->SUPER::openapi_dump($openapi_obj, %hints);
12 25         96 $res->{type} = 'boolean';
13              
14 25         97 return $res;
15             }
16              
17             sub _inhale
18             {
19 79     79   203 my ($self, $value) = @_;
20              
21 79         297 my $inhaled = $self->SUPER::_inhale($value);
22 79 100       385 return $inhaled if defined $inhaled;
23              
24 78 100       201 if (ref $value) {
25             $inhaled = 'boolean'
26 7 100   12   82 if none { $value == $_ } (JSON::PP::true, JSON::PP::false);
  12         193  
27             }
28             else {
29             $inhaled = 'boolean'
30 71 100   150   486 if none { $value eq $_ } (1, 0, !!1, !!0);
  150         362  
31             }
32              
33 78         463 return $inhaled;
34             }
35              
36             sub _exhale
37             {
38 58 100   58   339 return pop() ? JSON::PP::true : JSON::PP::false;
39             }
40              
41             1;
42