utf8;
use MooseX::Singleton;
use File::Spec::Functions qw(catfile catdir);
use URI::Template;
use JSON;
use namespace::autoclean;
our $VERSION = v0.16.3;
=head1 Name
PGXN::API - Maintain and serve a
ks for distributing any kind of release distributions and for
providing a lightweight static file JSON REST API.
PGXN::API provides a superset of the static file REST API, embellishing the
metadata i
=> 1, default => sub {
my $self = shift;
my $tmpl = $self->read_json_from(
catfile $self->doc_root, 'index.json'
);
return { map { $_ => URI::Template->new($tmpl->{$_}) } keys
);
}
sub update_root_json {
my $self = shift;
my $api = PGXN::API->instance;
say "Updating mirror root JSON" if $self->verbose;
# Augment and write index.json.
my $src = catfil
e $api->mirror_root, 'index.json';
my $dst = catfile $api->doc_root, 'index.json';
my $tmpl = $api->read_json_from($src);
$tmpl->{source} = "/src/{dist}/{dist}-{version}/";
$tmpl->{
}/';
$tmpl->{userlist} = '/users/{letter}.json';
($tmpl->{htmldoc} = $tmpl->{meta}) =~ s{/META[.]json$}{/{+docpath}.html};
$api->write_json_to($dst, $tmpl);
return $self;
}
sub cop
self = shift;
my $api = PGXN::API->instance;
my $tmpl = $api->read_json_from(catfile $api->mirror_root, 'index.json');
return { map { $_ => URI::Template->new($tmpl->{$_}) } keys %{ $tmpl
=~ /\s>f(?:[+]+|(?:c|.s|..t)[^ ]+)\sindex[.]json$/) {
# Always update the index JSON if it's mentioned.
$indexer->update_root_json;
}
elsif ($line =~ $user_re)
n {
my ($self, $fn) = shift->_rel_to_mirror(@_);
my $meta = PGXN::API->instance->read_json_from($fn);
my $zip_path = $self->download_for($meta);
# Validate it against the SHA1 che
::App::File;
use Plack::App::Directory;
use PGXN::API::Searcher;
use List::MoreUtils qw(any);
use JSON;
use Plack::Request;
use Encode;
use File::Spec::Functions qw(catdir);
use namespace::autoclean;
enable 'HTTPExceptions';
enable 'StackTrace', no_print_errors => 1;
enable 'JSONP', callback_key => 'callback';
enable sub {
my $app = shift;
sub
val && $val !~ /^\d+$/;
}
# Give 'em the results.
my $json = encode_json $searcher->search(
in => $in,
query => decode_utf8($q