| 1 | package WWW::AUR; | ||||||||||||||||||||||||||||
| 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 Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use Carp qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use File::Spec qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 12 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | # We must define these as soon as possible. They are used in other | ||||||||||||||||||||||||||||
| 12 | # WWW::AUR modules. Like the ones we use after this block... | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 12 | our $VERSION = '0.22'; | |||||||||||||||||||||||||||
| 15 | 12 | our $BASEPATH = '/tmp/WWW-AUR'; | |||||||||||||||||||||||||||
| 16 | 12 | our $HOST = 'aur.archlinux.org'; | |||||||||||||||||||||||||||
| 17 | 12 | our $UA = 'WWW::AUR::UserAgent'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 12 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 20 | 12 | our @EXPORT_OK = qw(_is_path_param _path_params | |||||||||||||||||||||||||||
| 21 | _category_name _category_index | ||||||||||||||||||||||||||||
| 22 | _useragent); | ||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 12 | ▶ | use WWW::AUR::RPC; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #---CONSTRUCTOR--- | ||||||||||||||||||||||||||||
| 28 | sub new | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 31 | 2 | return bless { _path_params( @_ ) }, $class | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | #---PUBLIC METHOD--- | ||||||||||||||||||||||||||||
| 35 | sub search | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
search: called CC=1 SCAR=2.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my ($self, $query) = @_; | |||||||||||||||||||||||||||
| 38 | 1 | my $found_ref = WWW::AUR::RPC::search( $query ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | require WWW::AUR::Package; | |||||||||||||||||||||||||||
| 41 | return map { | ||||||||||||||||||||||||||||
| 42 | 0 | WWW::AUR::Package->new( $_->{name}, info => $_, %$self ); | |||||||||||||||||||||||||||
| 43 | } @$found_ref; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | #---HELPER FUNCTION--- | ||||||||||||||||||||||||||||
| 47 | sub _def_wrapper_method | ||||||||||||||||||||||||||||
| 48 | 44 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_def_wrapper_method: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 44 | my ($name, $class) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 11 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 44 | ▶ | *{ "WWW::AUR::$name" } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 53 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 54 | 1 | eval "require $class"; | |||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | Carp::confess "Failed to load $class module:\n$@"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 1 | return eval { $class->new( @_, %$self ) }; | |||||||||||||||||||||||||||
| 59 | 44 | }; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 11 | _def_wrapper_method( 'find' => 'WWW::AUR::Package' ); | |||||||||||||||||||||||||||
| 63 | 11 | _def_wrapper_method( 'maintainer' => 'WWW::AUR::Maintainer' ); | |||||||||||||||||||||||||||
| 64 | 11 | _def_wrapper_method( 'iter' => 'WWW::AUR::Iterator' ); | |||||||||||||||||||||||||||
| 65 | 11 | _def_wrapper_method( 'login' => 'WWW::AUR::Login' ); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 68 | # UTILITY FUNCTIONS | ||||||||||||||||||||||||||||
| 69 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 70 | # These functions are used internally by other WWW::AUR modules... | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 11 | my %_IS_PATH_PARAM = map { ( $_ => 1 ) } | |||||||||||||||||||||||||||
| 73 | qw/ basepath dlpath extpath destpath /; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #---INTERNAL FUNCTION--- | ||||||||||||||||||||||||||||
| 76 | sub _is_path_param | ||||||||||||||||||||||||||||
| 77 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_is_path_param: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 1 | my ($name) = @_; | |||||||||||||||||||||||||||
| 79 | 1 | return $_IS_PATH_PARAM{ $name }; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | #---INTERNAL FUNCTION--- | ||||||||||||||||||||||||||||
| 83 | sub _path_params | ||||||||||||||||||||||||||||
| 84 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_path_params: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 85 | 3 | my @filterme = @_; | |||||||||||||||||||||||||||
| 86 | 3 | my %result; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | FILTER_LOOP: | ||||||||||||||||||||||||||||
| 89 | 3 | ▶ | while ( my $key = shift @filterme ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 1 | ▶ | next unless _is_path_param( $key ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 1 | ▶ | my $val = shift @filterme or last FILTER_LOOP; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 1 | $result{ $key } = $val; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Fill path parameters with default values if they are unspecified... | ||||||||||||||||||||||||||||
| 96 | 3 | our $BASEPATH; | |||||||||||||||||||||||||||
| 97 | 3 | ▶ | my $base = $result{ 'basepath' } || $BASEPATH; | ||||||||||||||||||||||||||
|
Condition66%2/3
$result{'basepath'} || $WWW::AUR::BASEPATH
MC/DC0%0/2
$result{'basepath'} || $WWW::AUR::BASEPATH
$result{'basepath'}
$WWW::AUR::BASEPATH
Truth table66%2/3
A || B
A= $result{'basepath'}B= $WWW::AUR::BASEPATH
| |||||||||||||||||||||||||||||
| 98 | 3 | return ( 'dlpath' => File::Spec->catdir( $base, 'src' ), | |||||||||||||||||||||||||||
| 99 | 'extpath' => File::Spec->catdir( $base, 'build' ), | ||||||||||||||||||||||||||||
| 100 | 'destpath' => File::Spec->catdir( $base, 'cache' ), | ||||||||||||||||||||||||||||
| 101 | %result ); | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 11 | my @_CATEGORIES = qw{ daemons devel editors emulators games gnome | |||||||||||||||||||||||||||
| 105 | i18n kde lib modules multimedia network office | ||||||||||||||||||||||||||||
| 106 | science system x11 xfce kernels fonts }; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #---INTERNAL FUNCTION--- | ||||||||||||||||||||||||||||
| 109 | sub _category_name | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_category_name: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 111 | 0 | my ($i) = @_; | |||||||||||||||||||||||||||
| 112 | 0 | $i -= 2; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | if ( $i >= 0 && $i <= $#_CATEGORIES ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i >= 0 and $i <= $#_CATEGORIES
MC/DC0%0/2
$i >= 0 and $i <= $#_CATEGORIES
$i >= 0
$i <= $#_CATEGORIES
Truth table0%0/3
A and B
A= $i >= 0B= $i <= $#_CATEGORIES
| |||||||||||||||||||||||||||||
| 114 | 0 | return $_CATEGORIES[$i]; | |||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||
| 116 | 0 | return 'undefined'; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | #---INTERNAL FUNCTION--- | ||||||||||||||||||||||||||||
| 121 | sub _category_index | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_category_index: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 123 | 0 | my ($name) = @_; | |||||||||||||||||||||||||||
| 124 | 0 | $name = lc $name; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | for my $i ( 0 .. $#_CATEGORIES ) { | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | return 2 + $i if $name eq $_CATEGORIES[ $i ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | Carp::croak "$name is not a valid category name"; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | #---INTERNAL FUNCTION--- | ||||||||||||||||||||||||||||
| 134 | # Create a user-agent object. The class name is specified in $UA. | ||||||||||||||||||||||||||||
| 135 | sub _useragent | ||||||||||||||||||||||||||||
| 136 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_useragent: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 137 | 10 | our $UA; | |||||||||||||||||||||||||||
| 138 | 10 | ▶ | eval "require $UA" or die; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 10 | return $UA->new(@_); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 11 | 1; | |||||||||||||||||||||||||||