blob: 5f3bcfa937feb12de715e3764def45f8113c3ac5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package App::ArchLinux::PackagerTools::Archweb;
use strictures;
use autodie;
use Function::Parameters;
use Log::Any qw($log);
use WWW::JSON;
use App::ArchLinux::PackagerTools::Cache;
use App::ArchLinux::PackagerTools::Config;
=head1 NAME
App::ArchLinux::PackagerTools::Archweb - ShortDesc
=head1 SYNOPSIS
use App::ArchLinux::PackagerTools::Archweb;
# synopsis...
=head1 DESCRIPTION
# longer description...
=head1 METHODS
=head2 new
my $archweb = App::ArchLinux::PackagerTools::Archweb->new();
Returns a new instance.
=cut
method new($class: $context, $deps = {}) {
$deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context);
$deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new($context);
my $base_url = $deps->{config}->get_config()->{archweb}->{base_url};
$deps->{wj} //= WWW::JSON->new(base_url => $base_url);
return $class->new_no_defaults($context, $deps);
}
method new_no_defaults($class: $context, $deps = {}) {
return $context->{$class} if defined $context->{$class};
my $self = {};
bless $self, $class;
$self->{deps} = $deps;
$context->{$class} = $self;
return $self;
}
=head2 Public Methods
=cut
=head3 get_maintainers
my $maintainers = $archweb->get_maintainers($pkgname);
print $maintainers->[0]->{name};
Return a list with the names of the maintainers of a package.
=cut
method get_maintainers($pkgname) {
my $cache_timeout = $self->{deps}->{config}->{archweb}->{cache_timeout};
my $json = $self->{deps}->{cache}->compute("archweb-package-json-$pkgname", $cache_timeout, sub {
$log->debugf("Gettings maintainers for pkgname: %s", $pkgname);
my $res = $self->{deps}->{wj}->get("/packages/search/json", {name => $pkgname});
my $json = $res->res;
croak $log->errorf("API returned no result for search for package %s", $pkgname) if $json->{results}->@* == 0 or !$res->success;
$log->debugf("Result is %s", $json);
return $json;
});
my $maintainers = $json->{results}->[0]->{maintainers};
$log->debugf("Found maintainers: %s", $maintainers);
return [map {name => $_}, $maintainers->@*];
}
1;
__END__
|