package Data::AnyXfer::JSON;
use v5.10.1;
use utf8;
use strict;
use warnings;
use base 'Cpanel::JSON::XS';
use Encode ();
use Path::Class ();
use Exporter qw/ import /;
our $VERSION = '0.07';
o
_json
encode_json_pretty
decode_json
decode_json_file
decode_json_handle
/;
our @EXPORT_OK = @EXPORT;
=head1 NAME
=encoding utf8
Data::AnyXfer::JSON - functions for encoding/decoding JSON
er::JSON qw/ decode_json /;
my $json = encode_json( { price => '£185pcm' } );
my $hash = decode_json( $json );
=head1 DESCRIPTION
This module provides simple wrappers around L<Cpanel::JSON::X
rom::JSON;
use v5.16.3;
use Moo::Role;
use MooX::Types::MooseLike::Base qw(:all);
use Carp;
use Path::Class;
use Data::AnyXfer::JSON qw/ decode_json /;
=head1 NAME
Data::AnyXfer::From::JSON - tr
ansfer from json sources
=head1 SYNOPSIS
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
extends 'Data::AnyXfer';
with 'Data::AnyXfer::From::JSON';
...
# Path::Class::Fil
e
has '+json' => ( default => sub { file('example.json'); } );
# Json string
has '+json' => ( default => sub { return '{"documents": [{"author": "Douglas Adams"}]'});
# Direct hash s
package Data::AnyXfer::Elastic::Import::File::Format::JSON;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
use Data::AnyXfer::JSON ( );
with 'Data::AnyXfer::Elastic::Import::File::Format';
=
yXfer::Elastic::Import::File::Format::JSON -
Elasticsearch import data storage format using JSON
=head1 SYNOPSIS
# data to printable characters
my $json_string = $format->serialise($data);
$format->deserialise($json_string);
=head1 DESCRIPTION
This class can be supplied to a
L<Data::AnyXfer::Elastic::Import::File> implementation
to store and retrieve data in JSON format from a storage
ath::Class;
use Path::Class::Dir;
use Scalar::Util ();
use Sys::Hostname ();
use Data::AnyXfer::JSON;
use DateTime ();
use constant methods => qw/
debug info
notice warning
error c
sub { {} },
);
# JSON decoder/encoder
has _coder => (
is => 'ro',
isa => 'Data::AnyXfer::JSON',
init_arg => undef,
default => sub { Data::AnyXfer::JSON->new->pretty(1)->a
}
my $json;
my $logger = $self->_fetch_logger($object);
if ( my $content = $args{content} ) {
# convert Search::Elasticsearch::Error (assumed) to
# json, we are only
package Data::AnyXfer::JsonToElasticsearch;
use v5.16.3;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
extends 'Data::AnyXfer';
with 'Data::AnyXfer::From::JSON';
with 'Data::AnyXfer::To::Ela
';
=head1 NAME
Data::AnyXfer::JsonToElasticsearch - transfer from JSON files to Elasticsearch
=head1 DESCRIPTION
This class combines the L<Data::AnyXfer::From::JSON> and
L<Data::AnyXfer::To::Elast
;
use MooX::Types::MooseLike::Base qw(:all);
use Carp;
use Data::AnyXfer ();
use Data::AnyXfer::JSON ();
=head1 NAME
Data::AnyXfer::Elastic::ServerDefinition - Stores node and cluster information
fer::Elastic::ServerDefinition
->load_json_file('servers.json');
# or from an open handle
open(my $open_fh, '<:encoding(UTF-8)', 'servers.json')
|| croak "Failed to open server de
ns file ($!)";
my @definitions =
Data::AnyXfer::Elastic::ServerDefinition
->load_json_handle($open_fh);
# Or define them programatically...
my $definition = Data::AnyXfer::El
Geo::JSON );
Validates the provided GeoJSON shape against Elasticsearch validator. Checks
for self-intersections, duplicate points etc.
=cut
sub validate_geo_shape {
my ( $self, $geojson ) = @
shape => {
coordinates => $geojson->coordinates,
type => $geojson->type,
}
}
}
_ES2;
use Carp;
use Moo::Role;
use MooX::Types::MooseLike::Base qw(:all);
use Clone ();
use JSON::XS ();
=head1 NAME
Data::AnyXfer::Elastic::Role::IndexInfo_ES2 - Role representing
Elasticsea
ompletion' ) {
# turn payloads on by default
$value->{payloads} = JSON::XS::true();
# XXX : backwards support to handle deprecated
# co
ata::AnyXfer::Elastic::Index;
use Data::AnyXfer::Elastic::ScrollHelper;
use Data::AnyXfer::JSON qw/encode_json_pretty/;
=head1 NAME
Data::AnyXfer::Elastic::Role::Project
=head1 SYNOPSIS
with '
:Elasticsearch;
use List::MoreUtils qw( uniq );
use Data::AnyXfer ();
use Data::AnyXfer::JSON qw( encode_json );
use Data::AnyXfer::Elastic::IndexInfo ();
use Data::AnyXfer::Elastic::Logger ();
us
"Argument 'file' does not exist at: $file" unless -f $file;
my $data = Data::AnyXfer::JSON::decode_json(
$file->slurp( iomode => '<:encoding(UTF-8)' ) );
# re-enable test flags if w
pdir->file($uuid) );
# serialise the arguments
my $argsjson = encode_json($args);
$file->spew( iomode => '>:raw', $argsjson );
# return the file location / object
return $file;
}
ase qw(:all);
use Carp;
use Scalar::Util ( );
use Data::AnyXfer::Elastic::Import::File::Format::JSON ( );
use Data::AnyXfer::Elastic::Import::Storage::TempDirectory ( );
with 'Data::AnyXfer::Elasti
pes.
If not supplied, defaults to an instance of
L<Data::AnyXfer::Elastic::Import::File::Format::JSON>,
=back
=head1 DATA INTERFACE
B<Please see L<Data::AnyXfer::Elastic::Import::File> for the
int
mport::File::Format'],
default => sub {
Data::AnyXfer::Elastic::Import::File::Format::JSON->new
},
);
has _content_body => (
is => 'rw',
isa => ArrayRef,
lazy => 1,
b