CPAN-Mini-Inject-REST
view release on metacpan or search on metacpan
lib/CPAN/Mini/Inject/REST/Controller/API/Version1_0.pm view on Meta::CPAN
package CPAN::Mini::Inject::REST::Controller::API::Version1_0;
use 5.010;
use Moose;
use Archive::Extract;
use File::Basename qw/basename/;
use File::Copy;
use File::Find::Rule;
use File::Spec::Functions qw/catdir catfile splitpath/;
use File::Temp;
use List::MoreUtils qw/uniq/;
use Parse::CPAN::Meta;
use Try::Tiny;
use namespace::autoclean;
BEGIN {extends 'Catalyst::Controller::REST'; }
__PACKAGE__->config(
namespace => 'api/1.0',
default => 'application/json',
);
=head1 NAME
CPAN::Mini::Inject::REST::Controller::API::Version1_0
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=head2 repository
/api/1.0/repository/File-Name-1.00.tar.gz
=cut
sub repository :Local :Args(1) :ActionClass('REST') {}
=head3 GET
Downloads a file from the repository. Returns status 404 if the file could
not be found.
=cut
sub repository_GET {
my ($self, $c, $file) = @_;
my $path = catfile($c->model('CMI')->config->get('repository'), 'authors/id/L/LO/LOCAL', $file);
if (-e $path) {
$c->serve_static_file($path);
} else {
$self->status_not_found(
$c,
message => "Cannot find $file in repository"
);
}
}
=head3 POST
Adds a file to the repository and injects it into the mirror. If the file can be
added, status 201 (Created) is returned with details of which modules the file
provides.
{
"provides": [
{
"version": "0.04",
"module": "hello"
}
( run in 1.527 second using v1.01-cache-2.11-cpan-39bf76dae61 )