line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use 5.014; |
3
|
17
|
|
|
17
|
|
10550
|
use strict; |
|
17
|
|
|
|
|
63
|
|
4
|
17
|
|
|
17
|
|
88
|
use warnings; |
|
51
|
|
|
|
|
253
|
|
|
51
|
|
|
|
|
389
|
|
5
|
51
|
|
|
17
|
|
245
|
use Moo::Role; |
|
51
|
|
|
|
|
130
|
|
|
134
|
|
|
|
|
539
|
|
6
|
134
|
|
|
17
|
|
328
|
use Types::Standard -all; |
|
134
|
|
|
|
|
437
|
|
|
134
|
|
|
|
|
458
|
|
7
|
51
|
|
|
17
|
|
6186
|
use GraphQL::MaybeTypeCheck; |
|
45
|
|
|
|
|
144
|
|
|
17
|
|
|
|
|
136
|
|
8
|
17
|
|
|
17
|
|
677748
|
|
|
17
|
|
|
|
|
50
|
|
|
17
|
|
|
|
|
205
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
GraphQL::Role::HashMappable - GraphQL object role |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with qw(GraphQL::Role::HashMappable); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# or runtime |
20
|
|
|
|
|
|
|
Role::Tiny->apply_roles_to_object($foo, qw(GraphQL::Role::HashMappable)); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Provides method for mapping code over a hash-ref. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 hashmap |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Given a hash-ref, returns a modified copy of the data. Returns undef if |
31
|
|
|
|
|
|
|
given that. Parameters: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item $item |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Hash-ref. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item $source |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Hash-ref of the source data for this hash. Will be used only for its keys. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item $code |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Code-ref. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Each value will be the original value returned by the given code-ref, |
50
|
|
|
|
|
|
|
which is called with C<$keyname>, C<$value>. Will call the code for all |
51
|
|
|
|
|
|
|
given keys, but not copy over any values not existing in original item. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
If code throws an exception, the message will have added to it information |
54
|
|
|
|
|
|
|
about which data element caused it. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
method hashmap(Maybe[HashRef] $item, HashRef $source, CodeRef $code) :ReturnType(Maybe[HashRef]) { |
59
|
34
|
50
|
|
34
|
1
|
85
|
return $item if !defined $item; |
|
34
|
50
|
|
|
|
65
|
|
|
34
|
100
|
|
|
|
48
|
|
|
34
|
100
|
|
|
|
58
|
|
|
34
|
100
|
|
|
|
76
|
|
|
34
|
|
|
|
|
261
|
|
|
34
|
|
|
|
|
214
|
|
60
|
|
|
|
|
|
|
my @errors = map qq{In field "$_": Unknown field.\n}, grep !exists $source->{$_}, sort keys %$item; |
61
|
|
|
|
|
|
|
my %newvalue = map { |
62
|
|
|
|
|
|
|
my @pair = eval { ($_ => scalar $code->($_, $item->{$_})) }; |
63
|
|
|
|
|
|
|
push @errors, qq{In field "$_": $@} if $@; |
64
|
|
|
|
|
|
|
exists $item->{$_} ? @pair : (); |
65
|
|
|
|
|
|
|
} sort keys %$source; |
66
|
|
|
|
|
|
|
die @errors if @errors; |
67
|
|
|
|
|
|
|
\%newvalue; |
68
|
|
|
|
|
|
|
} |
69
|
17
|
|
|
17
|
|
9607
|
|
|
17
|
|
|
|
|
43
|
|
|
17
|
|
|
|
|
197
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |