content =>
{
'application/json' =>
{
schema =>
content =>
{
"application/json" =>
{
schema =>
description => 'Although the `POST` method is supported, the API does not recognise JSON payload, but only query string.',
content =>
{
lf );
}
sub _object_type_to_class { return( shift->api->_object_type_to_class( @_ ) ); }
sub TO_JSON
{
my $self = shift( @_ );
my $hash = {};
if( $self->can( 'fields' ) )
{
m
my $class = ref( $self );
no strict 'refs';
my @methods = grep( !/^(?:new|init|TO_JSON|FREEZE|THAW|AUTOLOAD|DESTROY)$/, grep{ defined &{"${class}::$_"} } keys( %{"${class}::"} ) );
takes in the fields.json file, which is an aggregation of all the fields definition found, and can be edited manually.
# It then makes some adjustments, and produces the api.json file used by the mod
cumentE>
# <https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md>
# ./dev/fields.json
my $base_dir = file( __FILE__ )->parent;
my $field2type =
{
'file::author' =>
{
typ
},
};
$field2type->{metadata}->{def}->{resources} = $field2type->{resources};
# NOTE: fields.json is an adjusted aggregation of the fields mapping as documented by the MetaCPAN API documentation
$UA_OPTS $TYPE2CLASS $MODULE_RE );
use HTTP::Promise;
use HTTP::Promise::Headers;
use JSON;
use constant
{
API_URI => 'https://fastapi.metacpan.org',
METACPAN_CLIE
ch_https => 1,
default_headers => HTTP::Promise::Headers->new(
Accept => 'application/json,text/html,application/xhtml+xml;q=0.9,*/*;q=0.8',
),
ext_vary => 1,
max_body_in_memor
N::Filter' ) )
{
$filter = shift( @_ );
my $payload = $filter->as_json( encoding => 'utf8' ) ||
return( $self->pass_error( $filter->error ) );
ontaining all properties for each class used.
# From this file is created the fields.json file and then the api.json file
#
# This program is free software; you can redistribute it and/or modify it u
return( $data );
}
sub as_json
{
my $self = shift( @_ );
my $opts = $self->_get_args_as_hash( @_ );
my $data = $self->as_hash;
my $j = $self->new_json;
$j = $j->pretty if( $opt
s->{pretty} );
$j = $j->canonical if( $opts->{sort} );
my $json;
local $@;
# try-catch
eval
{
if( exists( $opts->{encoding} ) &&
defined( $opts->{encoding}
$json = $j->utf8->encode( $data );
}
else
{
$json = $j->encode( $data );
}
};
if( $@ )
{
return( $self->error( "Error encoding to JSON:
= Net::API::CPAN::Mock->new(
pretty => 1,
openapi => '/path/to/cpan-openapi-specs.json',
) || die( Net::API::CPAN::Mock->error, "\n" );
$mock->bind || die( $mock->error );
<port> to use when starting the mock CPAN API server.
=item * C<pretty>
Boolean. If true, the C<JSON> data returned by the mock server will be in a human-readable format.
=item * C<schema>
The Ope
ault, the value used is C<127.0.0.1>
This returns the current C<host> value.
=head2 json
Sets or gets the L<JSON> object.
=head2 load_specs
This takes a file path to an OpenAPI specifications, an
$self->{api} = undef unless( CORE::exists( $self->{api} ) );
# The name of the JSON property containing the array reference of data
# This is used for data in format other than
return( $self->error( "No search query set." ) ) if( !$filter->query );
my $json = $filter->as_json ||
return( $self->pass_error( $filter->error ) );
$req->method( 'PO
else
{
$req->method( 'GET' );
}
$req->headers->header( Accept => 'application/json' );
my $data = $api->fetch( $type => {
request => $req,
# We simply want the
:Generic );
use vars qw( $VERSION $DATA $TEST_DATA @STANDARD_HEADERS $DIFF_RAW_TEMPLATE $DIFF_JSON_TEMPLATE );
use curry;
use Changes::Version;
use DateTime;
use DateTime::Format::
$self->{port} ) );
$self->{pretty} = 0 unless( exists( $self->{pretty} ) );
# OpenAPI JSON specifications as perl data
$self->{specs} = undef unless( exists( $self->{specs} ) );
>load_specs( $self->{specs} ) || return( $self->pass_error );
}
$self->{json} = $self->new_json;
$self->{json}->pretty(1)->canonical(1) if( $self->pretty );
unless( $TEST_DATA )
{
/META.json b/var/tmp/target/MOMOTARO/Folklore-Japan-v1.2.3/META.json\n--- a/var/tmp/source/MOMOTARO/Folklore-Japan-v1.2.2/META.json\n+++ b/var/tmp/target/MOMOTARO/Folklore-Japan-v1.2.3/META.json\n\@\@
ns => 1,
source => "MOMOTARO/Folklore-Japan-v1.2.2/META.json",
target => "MOMOTARO/Folklore-Japan-v1.2.3/META.json",
},
{
deletions => 1,
diff =
/META.json b/var/tmp/target/MOMOTARO/Folklore-Japan-v1.2.3/META.json\n--- a/var/tmp/source/MOMOTARO/Folklore-Japan-v1.2.2/META.json\n+++ b/var/tmp/target/MOMOTARO/Folklore-Japan-v1.2.3/META.json\n\@\@
reference
cause =>
{
object => $some_object,
payload => $json_data,
},
});
print( "Error stack trace: ", $ex->stack_trace, "\n" );
# or
eval
{
$payload = $self->new_json->encode( $hash );
};
if( $@ )
{
return( $self->error( "An error occured while encoding JSON payload to remove scroller: $@" ) );
);
my $resp = $ua->delete( $uri,
Content => $payload,
Accept => 'application/json',
) || return( $self->pass_error( $ua->error ) );
return( $resp );
}
# e.g.: cXVlcnlUaGV
# Built with ./build/fields2api_def.pl
my $api_specs = $base_dir->child( 'api.json' );
my $specs = $api_specs->load_json || die( $api_specs->error );
my $mod_dir = $base_dir->child( 'modules' );
$mod
);
}
my $sample_file = $base_dir->child( "$object.json" );
my $sample_data;
$sample_data = $sample_file->load_json( boolean_values => [\0, \1] ) if( $sample_file->exists );
m
k( '${module_class}' );
};
use strict;
use warnings;
my \$test_data = Module::Generic->new->new_json->decode( join( '', <DATA> ) );
\$test_data->{debug} = \$DEBUG;
my \$this;
my \$obj = ${module_cla