line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
21
|
|
|
21
|
|
28828
|
use strict; |
|
21
|
|
|
|
|
49
|
|
|
21
|
|
|
|
|
718
|
|
2
|
21
|
|
|
21
|
|
117
|
use warnings; |
|
21
|
|
|
|
|
39
|
|
|
21
|
|
|
|
|
950
|
|
3
|
|
|
|
|
|
|
package MetaCPAN::Client::Role::Entity; |
4
|
|
|
|
|
|
|
# ABSTRACT: A role for MetaCPAN entities |
5
|
|
|
|
|
|
|
$MetaCPAN::Client::Role::Entity::VERSION = '2.029000'; |
6
|
21
|
|
|
21
|
|
112
|
use Moo::Role; |
|
21
|
|
|
|
|
42
|
|
|
21
|
|
|
|
|
190
|
|
7
|
|
|
|
|
|
|
|
8
|
21
|
|
|
21
|
|
24289
|
use JSON::PP; |
|
21
|
|
|
|
|
299639
|
|
|
21
|
|
|
|
|
1613
|
|
9
|
21
|
|
|
21
|
|
704
|
use Ref::Util qw< is_ref is_arrayref is_hashref >; |
|
21
|
|
|
|
|
1711
|
|
|
21
|
|
|
|
|
10208
|
|
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
|
72
|
|
|
72
|
1
|
53400
|
my ( $class, %args ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
72
|
|
|
|
|
348
|
my $known_fields = $class->_known_fields; |
31
|
|
|
|
|
|
|
|
32
|
72
|
|
|
|
|
216
|
for my $k ( @{ $known_fields->{scalar} } ) { |
|
72
|
|
|
|
|
322
|
|
33
|
|
|
|
|
|
|
$args{data}{$k} = $args{data}{$k}->[0] |
34
|
1306
|
50
|
33
|
|
|
9157
|
if is_arrayref( $args{data}{$k} ) and @{$args{data}{$k}} == 1; |
|
0
|
|
|
|
|
0
|
|
35
|
|
|
|
|
|
|
|
36
|
1306
|
100
|
|
|
|
2694
|
if ( JSON::PP::is_bool($args{data}{$k}) ) { |
|
|
50
|
|
|
|
|
|
37
|
211
|
|
|
|
|
1506
|
$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
|
72
|
|
|
|
|
495
|
for my $k ( @{ $known_fields->{arrayref} } ) { |
|
72
|
|
|
|
|
264
|
|
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
|
151
|
50
|
33
|
|
|
665
|
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
|
151
|
50
|
|
|
|
430
|
unless is_arrayref( $args{data}{$k} ); # warn? |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
72
|
|
|
|
|
537
|
for my $k ( @{ $known_fields->{hashref} } ) { |
|
72
|
|
|
|
|
229
|
|
56
|
|
|
|
|
|
|
delete $args{data}{$k} |
57
|
153
|
100
|
|
|
|
392
|
unless is_hashref( $args{data}{$k} ); # warn? |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
72
|
|
|
|
|
1668
|
return \%args; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new_from_request { |
64
|
102
|
|
|
102
|
1
|
12538
|
my ( $class, $request, $client ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
102
|
|
|
|
|
516
|
my $known_fields = $class->_known_fields; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return $class->new( |
69
|
|
|
|
|
|
|
( defined $client ? ( client => $client ) : () ), |
70
|
|
|
|
|
|
|
data => { |
71
|
|
|
|
|
|
|
map +( defined $request->{$_} ? ( $_ => $request->{$_} ) : () ), |
72
|
101
|
100
|
|
|
|
495
|
map +( @{ $known_fields->{$_} } ), |
|
303
|
100
|
|
|
|
6470
|
|
73
|
|
|
|
|
|
|
qw< scalar arrayref hashref > |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |