| 1 | package GraphQL::Houtou::Role::HashMappable; | ||||||||||
| 2 | |||||||||||
| 3 | 62 | ▶ | use 5.014; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 62 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 62 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 62 | ▶ | use Role::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # Utility helpers for hash-shaped GraphQL values and field maps. | ||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub hashmap { | ||||||||
|
Subroutine
hashmap: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 12 | 0 | my ($self, $item, $source, $code) = @_; | |||||||||
| 13 | 0 | ▶ | return $item if !defined $item; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | |||||||||||
| 15 | my @errors = map qq{In field "$_": Unknown field.\n}, | ||||||||||
| 16 | 0 | grep { !exists $source->{$_} } sort keys %$item; | |||||||||
| 17 | my %newvalue = map { | ||||||||||
| 18 | 0 | my @pair = eval { ($_ => scalar $code->($_, $item->{$_})) }; | |||||||||
| 19 | 0 | ▶ | push @errors, qq{In field "$_": $@} if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | ▶ | exists $item->{$_} ? @pair : (); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | } sort keys %$source; | ||||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | die @errors if @errors; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | return \%newvalue; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 62 | 1; | |||||||||