kage DiaColloDB::EnumFile::MMap;
use DiaColloDB::EnumFile;
use DiaColloDB::Utils qw(:fcntl :file :json :regex);
use File::Map qw(map_handle);
use Fcntl qw(:DEFAULT :seek);
use strict;
##=============
upgrades applied to $dbdir
## + list is created by parsing "upgraded" field from "$dbdir/header.json"
## + if the upgrade-item "by" keyword inherits from DiaColloDB::Upgrade::Base,
## a new obje
B<OR>
a JSON-string encoding such a HASH-ref.
Options C<%opts> are as for the L<profile()|/profile> method (mostly ignored),
and also:
slice2keys => \%slice2keys, ##-- target f2-items or JSON-string
rror;
use strict;
use warnings;
use Data::Dumper;
use English qw( -no_match_vars );
use JSON qw( decode_json );
use Scalar::Util qw( reftype );
use XML::Simple qw( XMLin );
__PACKAGE__->follow_best
=~ /json/xmsi ) {
$message = eval { return decode_json($raw_message); };
}
# try a little harder...
if ( !$message || $EVAL_ERROR ) {
$message = eval { return decode_json($ra
_END__
=pod
=head1 NAME
C<Amazon::API::Error>
=head1 SYNOPSIS
my $result = eval {
decode_json(
$cwe->PutPermission(
{ Action => "PutEvents",
Principal => "12345465
$VERSION = '1.1.0';
use Moose;
use 5.14.2;
use DBI qw(:utils);
use Digest::MD5 qw(md5_hex);
use JSON::PP;
use Zonemaster::Backend::Validator qw( untaint_ipv6_address );
use Zonemaster::Backend::Err
);
use File::Find;
use File::Path qw(make_path);
use Getopt::Long qw(:config no_ignore_case);
use JSON;
use List::MoreUtils qw( first_index );
use List::Util qw( max );
use Pod::Usage;
use Pod::Text;
################################
sub fetch_json_file {
########################################################################
my ($path) = @_;
my $json;
open my $fh, '<', $path
or croak
' . $path;
{
local $RS = undef;
$json = JSON->new->utf8->decode(<$fh>);
}
close $fh
or croak 'could not close ' . $path;
return $json;
}
#######################################
Corpus::Filters qw(:defaults);
use DiaColloDB::Persistent;
use DiaColloDB::Utils qw(:math :fcntl :json :sort :pack :regex :file :si :run :env :temp :jobs);
#use DiaColloDB::Temp::Vec;
use DiaColloDB::
of dist files for this db
sub diskFiles {
my $coldb = shift;
return ("$coldb->{dbdir}/header.json", map {$_->diskFiles} grep {UNIVERSAL::can(ref($_),'diskFiles')} values %$coldb);
}
##==========
pts{slice2keys}, which is EITHER
## - a HASH-ref {$slice1=>\@keys1, ...},
## OR
## - a JSON-string encoding a such a HASH-ref
## + %opts, as for profile(), except:
## (
## ##-- sele
plied to C<$dbdir>.
Returned list is created by parsing C<"upgraded"> field from C<"$dbdir/header.json">.
If the upgrade-item C<"by"> keyword is the name of a package inheriting from L<DiaColloDB::Upg
is_hash is_array);
use Carp;
use Data::Dumper;
use English qw(-no_match_vars);
use JSON qw(decode_json encode_json);
use Scalar::Util qw(reftype blessed);
use List::Util qw(any none);
use POSIX qw(s
rue false) ) {
return {
0 => JSON::false,
1 => JSON::true,
true => JSON::true,
false => JSON::false,
}->{$data};
}
return
ime),
to_template_var('class') => $shape_class,
to_template_var('shape') => JSON->new->pretty->encode($shape),
to_template_var('service') => $service,
to_template_va
::Botocore::Shape);
use strict;
use warnings;
use JSON qw(decode_json);
our $SHAPE = <<'SHAPE';
@shape@
SHAPE
our $SHAPE_DEFINITION = decode_json($SHAPE);
########################################
ixedLen;
use DiaColloDB::EnumFile;
use DiaColloDB::Logger;
use DiaColloDB::Utils qw(:fcntl :file :json :regex :pack);
use Fcntl qw(:DEFAULT :seek);
use strict;
##=====================================
-----
## I/O: JSON
## + mostly INHERITED from DiaCollocDB::Persistent
## $obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts)
## + guts for loadJsonString(), loadJsonFile()
sub loadJsonData {
my $
that = shift;
my $dprf = $that->DiaColloDB::Persistent::loadJsonData(@_);
bless($_,'DiaColloDB::Profile') foreach (grep {defined($_)} @$dprf{qw(prf1 prf2)});
return $dprf;
}
##-----------------
===================================================
## JSON: load
$data = PACKAGE::loadJsonString( $string,%opts);
$data = PACKAGE::loadJsonFile($filename_or_handle,%opts);
##=================
=======================================================
## JSON: save
$str = PACKAGE::saveJsonString($data);
$bool = PACKAGE::saveJsonFile($data,$filename_or_handle,%opts);
##=================
qw(fcflags fcgetfl fcread fcwrite fctrunc fccreat fcperl fcopen)],
json => [qw(loadJsonString loadJsonFile saveJsonString saveJsonFile)],
sort => [qw(csort_to csortuc_to sortCmd)],
run => [qw(c
======================================================================
## I/O: JSON
$obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts);
##======================================================
oDB::Profile::Multi: I/O: JSON
=pod
=head2 I/O: JSON
=over 4
=item loadJsonData
$obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts);
guts for loadJsonString(), loadJsonFile()
=back
=cut
##---
dclass, ##-- DiaColloDB::Document subclass for loading (OVERRIDE force 'DiaColloDB::Document::JSON')
## dopts => \%opts, ##-- options for $dclass->fromFile() (override default={})
## c
##-- strong overrides
dclass => 'DiaColloDB::Document::JSON',
);
$corpus->{filters} = DiaColloDB::Corpus::Filters->new() i
ions: dclass, files, opened
$corpus->{opened} = 1;
$corpus->{dclass} = 'DiaColloDB::Document::JSON';
delete $corpus->{files};
return $corpus;
}
## $bool = $corpus->close()
sub close {
my $
======================================================================
## I/O: JSON
$obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts);
##======================================================
loDB::Profile::Diff: I/O: JSON
=pod
=head2 I/O: JSON
=over 4
=item loadJsonData
$obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts);
guts for loadJsonString(), loadJsonFile()
=back
=cut
##---
-----
## I/O: JSON
## + mostly INHERITED from DiaCollocDB::Persistent
## $obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts)
## + guts for loadJsonString(), loadJsonFile()
sub loadJsonData {
my $
that = shift;
my $mp = $that->DiaColloDB::Persistent::loadJsonData(@_);
foreach (@{$mp->{profiles}//[]}) {
bless($_,'DiaColloDB::Profile::Diff');
bless($_->{prf1}, 'DiaColloDB::Profile')
{body}//1);
$fh->print("<script type=\"text/javascript\">$opts{qinfo}=", DiaColloDB::Utils::saveJsonString($mp->{qinfo}, pretty=>0), ";</script>\n")
if ($mp->{qinfo} && ($opts{qinfo} //= 'qinfo'
se List::MoreUtils qw[uniq none];
use Locale::TextDomain qw[Zonemaster-Engine];
use Readonly;
use JSON::PP;
use Net::IP::XS;
use Zonemaster::Engine::Profile;
use Zonemaster::Engine::Constants qw[:ip]
my $json = JSON::PP->new->canonical->pretty;
if ( $p1 and scalar $p1->answer ) {
my @answer1 = map { lc $_->string } sort $p1->answer;
$answer1_string = $json->enco
my @answer2 = map { lc $_->string } sort $p2->answer;
$answer2_string = $json->encode( \@answer2 );
}
if ( $answer1_string eq $answer2_string ) {
es should call this from $up->upgrade()
## + default implementation just backs up "$dbdir/header.json", emitting a warning
## if $up->{backup} is false
sub backup {
my $up = shift;
##-- were
using backup directory $backd/");
$up->info("backing up $dbdir/header.json");
DiaColloDB::Utils::copyto_a("$dbdir/header.json", $backd)
or $up->logconfess("updateHeader(): failed to backup h
==========
## Utilities
## \%hdr = $CLASS_OR_OBJECT->dbheader($dbdir?)
## + reads $dbdir/header.json
## + default uses cached $CLASS_OR_OBJECT->{hdr} if available
sub dbheader {
my ($up,$dbdir) =
-----
## I/O: JSON
## + mostly INHERITED from DiaCollocDB::Persistent
## $obj = $CLASS_OR_OBJECT->loadJsonData( $data,%opts)
## + guts for loadJsonString(), loadJsonFile()
sub loadJsonData {
my $
that = shift;
my $mp = $that->DiaColloDB::Persistent::loadJsonData(@_);
bless($_,'DiaColloDB::Profile') foreach (@{$mp->{profiles}//[]});
return $mp;
}
##-------------------------------------
{body}//1);
$fh->print("<script type=\"text/javascript\">$opts{qinfo}=", DiaColloDB::Utils::saveJsonString($mp->{qinfo}, pretty=>0), ";</script>\n")
if ($mp->{qinfo} && ($opts{qinfo} //= 'qinfo'