| 1 | package WWW::AUR::RPC; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings 'FATAL' => 'all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use JSON qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Carp qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use WWW::AUR::URI qw( rpc_uri ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use WWW::AUR qw( _category_name _useragent ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | my %_RENAME_FOR = ( 'Description' => 'desc', | |||||||||||||||||||||||||||
| 13 | 'NumVotes' => 'votes', | ||||||||||||||||||||||||||||
| 14 | 'CategoryID' => 'category', | ||||||||||||||||||||||||||||
| 15 | 'OutOfDate' => 'outdated', | ||||||||||||||||||||||||||||
| 16 | 'FirstSubmitted' => 'ctime', | ||||||||||||||||||||||||||||
| 17 | 'LastModified' => 'mtime', | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | #---HELPER FUNCTION--- | ||||||||||||||||||||||||||||
| 21 | # Purpose: Map JSON package info keys to their new names... | ||||||||||||||||||||||||||||
| 22 | sub _munge_result | ||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my ($info_ref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_munge_result: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | my %result; | |||||||||||||||||||||||||||
| 27 | 0 | for my $key ( keys %$info_ref ) { | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $newkey = $_RENAME_FOR{ $key } || lc $key; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_RENAME_FOR{$key} || lc $key
MC/DC0%0/2
$_RENAME_FOR{$key} || lc $key
$_RENAME_FOR{$key}
lc $key
Truth table0%0/3
A || B
A= $_RENAME_FOR{$key}B= lc $key
| |||||||||||||||||||||||||||||
| 29 | 0 | $result{ $newkey } = $info_ref->{ $key }; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | $result{category} = _category_name( $result{category} ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | return \%result; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #---CLASS/OBJECT METHOD--- | ||||||||||||||||||||||||||||
| 38 | sub info | ||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 7 | ▶ | my ($name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
info: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 7 | my $uri = rpc_uri( "info", $name ); | |||||||||||||||||||||||||||
| 43 | 7 | my $ua = _useragent(); | |||||||||||||||||||||||||||
| 44 | 7 | $ua->InitTLS; | |||||||||||||||||||||||||||
| 45 | 7 | my $resp = $ua->get( $uri ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | Carp::croak 'Failed to call info AUR RPC: ' . $resp->status_line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | unless $resp->is_success; | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | my $json = JSON->new; | |||||||||||||||||||||||||||
| 51 | 7 | my $data = $json->decode( $resp->content ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 7 | ▶ | if ( $data->{type} eq "error" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 54 | 7 | Carp::croak "Remote error: $data->{results}"; | |||||||||||||||||||||||||||
| 55 | } elsif ( $data->{resultcount} == 0 ) { | ||||||||||||||||||||||||||||
| 56 | 0 | return undef; | |||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||
| 58 | 0 | return _munge_result( $data->{results} ); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | sub multiinfo | ||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my (@names) = @_; | ||||||||||||||||||||||||||
|
Subroutine
multiinfo: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $uri = rpc_uri( "multiinfo", @names ); | |||||||||||||||||||||||||||
| 67 | 0 | my $ua = _useragent(); | |||||||||||||||||||||||||||
| 68 | 0 | $ua->InitTLS; | |||||||||||||||||||||||||||
| 69 | 0 | my $resp = $ua->get( $uri ); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | Carp::croak 'Failed to call multiinfo AUR RPC: ' . $resp->status_line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | unless $resp->is_success; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | my $json = JSON->new; | |||||||||||||||||||||||||||
| 75 | 0 | my $data = $json->decode( $resp->content ); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $data->{type} eq "error" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | Carp::croak "Remote error: $data->{results}"; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | return map { _munge_result($_) } @{$data->{results}}; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub search | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 1 | ▶ | my ($query) = @_; | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=7 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | my $regexp; | |||||||||||||||||||||||||||
| 89 | 1 | ▶ | if ( $query =~ /\A\^/ || $query =~ /\$\z/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$query =~ /\A\^/ or $query =~ /\$\z/
MC/DC0%0/2
$query =~ /\A\^/ or $query =~ /\$\z/
$query =~ /\A\^/
$query =~ /\$\z/
Truth table33%1/3
A or B
A= $query =~ /\A\^/B= $query =~ /\$\z/
| |||||||||||||||||||||||||||||
| 90 | 0 | $regexp = eval { qr/$query/ }; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | Carp::croak qq{Failed to compile "$query" into regexp:\n$@}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | $query =~ s/\A\^//; | |||||||||||||||||||||||||||
| 96 | 0 | $query =~ s/\$\z//; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 1 | my $uri = rpc_uri( 'search', $query ); | |||||||||||||||||||||||||||
| 100 | 1 | my $ua = _useragent(); | |||||||||||||||||||||||||||
| 101 | 1 | $ua->InitTLS; | |||||||||||||||||||||||||||
| 102 | 1 | my $resp = $ua->get( $uri ); | |||||||||||||||||||||||||||
| 103 | 1 | ▶ | Carp::croak 'Failed to search AUR using RPC: ' . $resp->status_line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | unless $resp->is_success; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 1 | my $json = JSON->new; | |||||||||||||||||||||||||||
| 107 | 1 | my $data = $json->decode( $resp->content ); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 1 | ▶ | if ( $data->{type} eq 'error' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | Carp::croak "Remote error: $data->{results}"; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my $results = [ map { _munge_result( $_ ) } @{ $data->{results} } ]; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ( $regexp ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $results = [ grep { $_->{name} =~ /$regexp/ } @$results ]; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | return $results; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub msearch | ||||||||||||||||||||||||||||
| 123 | { | ||||||||||||||||||||||||||||
| 124 | 1 | ▶ | my ($name) = @_; | ||||||||||||||||||||||||||
|
Subroutine
msearch: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 1 | my $aururi = rpc_uri( 'msearch', $name ); | |||||||||||||||||||||||||||
| 127 | 1 | my $ua = _useragent(); | |||||||||||||||||||||||||||
| 128 | 1 | $ua->InitTLS; | |||||||||||||||||||||||||||
| 129 | 1 | my $resp = $ua->get( $aururi ); | |||||||||||||||||||||||||||
| 130 | 1 | ▶ | Carp::croak qq{Failed to lookup maintainer using RPC:\n} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | . $resp->status_line unless $resp->is_success; | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1 | my $json = JSON->new; | |||||||||||||||||||||||||||
| 134 | 1 | my $json_ref = $json->decode( $resp->content ); | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | ▶ | if ( $json_ref->{type} eq 'error' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 1 | Carp::croak "Remote error: $json_ref->{results}"; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | return [ map { _munge_result( $_ ) } @{ $json_ref->{results} } ]; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 11 | 1; | |||||||||||||||||||||||||||