line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
21
|
|
|
21
|
|
30244
|
use strict; |
|
21
|
|
|
|
|
51
|
|
|
21
|
|
|
|
|
677
|
|
2
|
21
|
|
|
21
|
|
111
|
use warnings; |
|
21
|
|
|
|
|
43
|
|
|
21
|
|
|
|
|
1001
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::Client::Role::Entity; |
4
|
|
|
|
|
|
|
# ABSTRACT: A role for MetaCPAN entities |
5
|
|
|
|
|
|
|
$MetaCPAN::Client::Role::Entity::VERSION = '2.028000'; |
6
|
21
|
|
|
21
|
|
121
|
use Moo::Role; |
|
21
|
|
|
|
|
41
|
|
|
21
|
|
|
|
|
173
|
|
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
23839
|
use JSON::PP; |
|
21
|
|
|
|
|
302964
|
|
|
21
|
|
|
|
|
1647
|
|
9
|
21
|
|
|
21
|
|
665
|
use Ref::Util qw< is_ref is_arrayref is_hashref >; |
|
21
|
|
|
|
|
1700
|
|
|
21
|
|
|
|
|
10599
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has data => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
required => 1, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has client => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
lazy => 1, |
19
|
|
|
|
|
|
|
builder => '_build_client', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _build_client { |
23
|
0
|
|
|
0
|
|
0
|
require MetaCPAN::Client; |
24
|
0
|
|
|
|
|
0
|
return MetaCPAN::Client->new(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub BUILDARGS { |
28
|
68
|
|
|
68
|
1
|
50380
|
my ( $class, %args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
68
|
|
|
|
|
301
|
my $known_fields = $class->_known_fields; |
31
|
|
|
|
|
|
|
|
32
|
68
|
|
|
|
|
168
|
for my $k ( @{ $known_fields->{scalar} } ) { |
|
68
|
|
|
|
|
283
|
|
33
|
|
|
|
|
|
|
$args{data}{$k} = $args{data}{$k}->[0] |
34
|
1158
|
50
|
33
|
|
|
8431
|
if is_arrayref( $args{data}{$k} ) and @{$args{data}{$k}} == 1; |
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
|
36
|
1158
|
100
|
|
|
|
2618
|
if ( JSON::PP::is_bool($args{data}{$k}) ) { |
|
|
50
|
|
|
|
|
|
37
|
195
|
|
|
|
|
1388
|
$args{data}{$k} = !!$args{data}{$k}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ( is_ref( $args{data}{$k} ) ) { |
40
|
0
|
|
|
|
|
0
|
delete $args{data}{$k}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
68
|
|
|
|
|
440
|
for my $k ( @{ $known_fields->{arrayref} } ) { |
|
68
|
|
|
|
|
246
|
|
45
|
|
|
|
|
|
|
# fix the case when we expect an array ref but get a scalar because |
46
|
|
|
|
|
|
|
# the result array had one element and we received a scalar |
47
|
141
|
50
|
33
|
|
|
668
|
if ( defined($args{data}{$k}) and !is_ref($args{data}{$k}) ) { |
48
|
0
|
|
|
|
|
0
|
$args{data}{$k} = [ $args{data}{$k} ] |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
delete $args{data}{$k} |
52
|
141
|
50
|
|
|
|
365
|
unless is_arrayref( $args{data}{$k} ); # warn? |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
68
|
|
|
|
|
139
|
for my $k ( @{ $known_fields->{hashref} } ) { |
|
68
|
|
|
|
|
191
|
|
56
|
|
|
|
|
|
|
delete $args{data}{$k} |
57
|
143
|
100
|
|
|
|
396
|
unless is_hashref( $args{data}{$k} ); # warn? |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
68
|
|
|
|
|
1596
|
return \%args; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new_from_request { |
64
|
98
|
|
|
98
|
1
|
12733
|
my ( $class, $request, $client ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
98
|
|
|
|
|
562
|
my $known_fields = $class->_known_fields; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $class->new( |
69
|
|
|
|
|
|
|
( defined $client ? ( client => $client ) : () ), |
70
|
|
|
|
|
|
|
data => { |
71
|
|
|
|
|
|
|
map +( defined $request->{$_} ? ( $_ => $request->{$_} ) : () ), |
72
|
97
|
100
|
|
|
|
484
|
map +( @{ $known_fields->{$_} } ), |
|
291
|
100
|
|
|
|
5966
|
|
73
|
|
|
|
|
|
|
qw< scalar arrayref hashref > |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |