| 1 | package WWW::Hetzner::Role::JSONBool; | ||||||||||
| 2 | # ABSTRACT: Helper role for JSON boolean values in the Hetzner API | ||||||||||
| 3 | |||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||
| 5 | |||||||||||
| 6 | 60 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 60 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | # The Cloud API only accepts JSON booleans for boolean fields; a Perl 0/1 | ||||||||||
| 11 | # would be encoded as a JSON number and rejected as invalid_input (karr #30). | ||||||||||
| 12 | # Accepts plain truthy/falsy values, \0/\1 and JSON boolean objects alike. | ||||||||||
| 13 | 34 | ▶ | sub _json_bool { | ||||||||
|
Subroutine
_json_bool: called CC=3 SCAR=11.0
| |||||||||||
| 14 | 34 | my ($value) = @_; | |||||||||
| 15 | 34 | ▶ | $value = $$value if ref $value eq 'SCALAR'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 34 | ▶ | return $value ? \1 : \0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 60 | 1; | |||||||||
| 21 | |||||||||||
| 22 | __END__ | ||||||||||