sion;
our $VERSION = 'v0.900.1'; # VERSION
use v5.10.1;
use strict;
use warnings;
use Carp;
use JSON;
use HTTP::Tiny;
use constant DEFAULT_ENDPOINT => 'https://api.sendgrid.com/v3/mail/send';
use
keep_alive => 0,
default_headers => {
'Content-Type' => 'application/json',
'Authorization' => "Bearer $api_key",
},
);
my $response = $http->
{data}{mail_settings}{sandbox_mode} = { enable => JSON::true };
return $self->send(%args);
}
sub _payload {
my ($self) = @_;
return JSON->new->utf8->canonical->encode( $self->{data} );
}
my %data=map split,@data;
my $json=qx( $exe{curl} -s https://api.coinmarketcap.com/v1/ticker/ );
eval "require JSON;"; croak if $@;
my $arr=JSON::decode_json($json);
for my $c (qw(BTC LTC XBT
ns/mime-types-complete-list/
croak "todo: ext2mime not yet implemented";
#return "application/json";#feks
}
sub base64 ($;$) { #
if ($] >= 5.006) {
require bytes;
croak "base64 failed:
ammar tree, which is simply a
nested data structure.
The grammar tree can be serialized to YAML, JSON, Perl, or any other
programming language. This makes it extremely portable. Pegex::Grammar has
me
>>
Serialize the current grammar tree to YAML.
=item C<< $compiler->to_json() >>
Serialize the current grammar tree to JSON.
=item C<< $compiler->to_perl() >>
Serialize the current grammar tree
it trivial to update your grammar module after making
changes to the grammar file.
See L<Pegex::JSON> for an example.
=head1 AUTHOR
Ingy döt Net <ingy@cpan.org>
=head1 COPYRIGHT AND LICENSE
Cop
= (1 << 8),
UCL_CHARACTER_ESCAPE = (1 << 9),
UCL_CHARACTER_KEY_SEP = (1 << 10),
UCL_CHARACTER_JSON_UNSAFE = (1 << 11),
UCL_CHARACTER_UCL_UNSAFE = (1 << 12)
};
struct ucl_macro {
char *name;
un
erdata_dtor dtor;
ucl_userdata_emitter emitter;
};
/**
* Unescape json string inplace
* @param str
*/
size_t ucl_unescape_json_string (char *str, size_t len);
/**
* Handle include macro
* @par
_emitter emit_type);
/**
* Serialize string as JSON string
* @param str string to emit
* @param buf target buffer
*/
void ucl_elt_string_write_json (const char *str, size_t size,
struct ucl_emi
e current tutorials.
=over
=item L<Pegex::Tutorial::JSON>
This is a very in-depth tutorial of the creation of the module L<Pegex::JSON>
(a JSON decoder that uses Pegex) and the thought that went in
guages (DSLs) that need to be used in several programming languages and
environments. Things like JSON, YAML, Markdown etc. It also great for writing
parsers/compilers that only need to work in one la
-----------------. .------.
|noun: /world/ | | Foo grammar tree | | JSON |
| | '--------------------' '------'
....................
ster/testml.pgx.yaml>
The grammar can also be precompiled to JSON:
L<https://github.com/ingydotnet/testml-pgx/blob/master/testml.pgx.json>
Pegex::Compiler further compiles this into a Perl 5 only gr
ema => ['Core', 'Perl'])
->dump_string($self->tree);
}
sub to_json {
require JSON::PP;
my $self = shift;
JSON::PP
->new
->utf8
->canonical
->pretty
#readme
=encoding utf8
=head1 How to write a JSON Parser in Pegex
This document details the creation of the CPAN module: L<Pegex::JSON> which is
a JSON parser/decoder written in Perl using the Pege
ngydotnet/pegex-json-pm>.
=head1 Test First
Have a look at
L<https://github.com/ingydotnet/pegex-json-pm/blob/master/test/test.t>.
This simple test has a bunch of small pieces of
JSON and their YAML
equivalents. It asserts that when the JSON is decoded, it
will match the YAML.
The test is written in a testing language known as TestML. TestML just happens
to also use Pegex in its compiler. Both
rom a Pegex grammar for parsing JSON:
json: hash | array
array: / LSQUARE / ( node* % / COMMA / ) (
/ RSQUARE / | `missing ']'` )
This is saying: "json is either a hash or array. arr
lib ../blib/arch);
use feature ":5.10";
use Config::UCL;
use JSON::PP qw(encode_json);
my $hash = ucl_load("key1 : val1");
say encode_json $hash;
my $text = ucl_dump($hash);
say $text;
my $data1 =
Config::UCL;
use JSON::PP;
my $hash = ucl_load('var1 = "${var1}"; var2 = "$var2"',
{
ucl_parser_register_variables => [ var1 => 'val1', val2 => 'val2' ],
}
);
say JSON::PP->new->canon
tr*'],
pos => 0,
completion => $complete_path,
},
);
my @drivers = qw(json yaml org);
$SPEC{loadobj} = {
v => 1.1,
summary => 'Load tree object',
description =
y $fs;
if ($driver eq 'json') {
return [501, "Not implemented"];
#require Data::CSel::WrapStruct;
#require JSON::MaybeXS;
#my $json = JSON::MaybeXS->new(allow_nonre
f=>1, canonical=>1);
#my $data = $json->decode(File::Slurper::Dash::read_text($source));
#$tree = Data::CSel::WrapStruct::wrap_struct($data);
} elsif ($driver eq 'yaml') {
use Log::ger;
use parent qw(Term::Shell);
use Color::ANSI::Util qw(ansifg);
use Data::Clean::ForJSON;
use Path::Naive qw(concat_and_normalize_path);
use Perinci::Sub::Util qw(err);
use Term::Detect:
$text;
}
}
sub _json_obj {
state $json;
if (!$json) {
require JSON::MaybeXS;
$json = JSON::MaybeXS->new->allow_nonref;
}
$json;
}
sub json_decode {
my ($sel
@_;
$self->_json_obj->decode($arg);
}
sub json_encode {
my ($self, $arg) = @_;
my $data = $cleanser->clone_and_clean($arg);
#use Data::Dump; dd $data;
$self->_json_obj->encode($da
ucl_object_lua_import (lua_State *L, int idx);
/**
* Import UCL object from lua state, escaping JSON strings
* @param L lua state
* @param idx index of object at the lua stack to convert to UCL
*
#include <iostream>
#include <tuple>
#include "ucl.h"
// C++11 API inspired by json11: https://github.com/dropbox/json11/
namespace ucl {
struct ucl_map_construct_t { };
constexpr ucl_map_construc
t_fromstring_common (value, 0, UCL_STRING_RAW));
}
// Implicit constructor: anything with a to_json() function.
template <class T, class = decltype(&T::to_ucl)>
Ucl(const T &t) : Ucl(t.to_ucl())
return lookup(key);
}
// Serialize.
void dump (std::string &out, ucl_emitter_t type = UCL_EMIT_JSON) const
{
struct ucl_emitter_functions cbdata;
cbdata = Ucl::default_emit_funcs();
cbdata.
rsing and emitting functions
*
* UCL is universal configuration language, which is a form of
* JSON with less strict rules that make it more comfortable for
* using as a configuration language
*/
bject_emit().
*/
typedef enum ucl_emitter {
UCL_EMIT_JSON = 0, /**< Emit fine formatted JSON */
UCL_EMIT_JSON_COMPACT, /**< Emit compacted JSON */
UCL_EMIT_CONFIG, /**< Emit human readable config
UCL_STRING_RAW = 0x0, /**< Treat string as is */
UCL_STRING_ESCAPE = (1 << 0), /**< Perform JSON escape */
UCL_STRING_TRIM = (1 << 1), /**< Trim leading and trailing whitespaces */
UCL_STRI
bject(obj) && (
sv_isa(obj, "JSON::PP::Boolean")
|| sv_isa(obj, "Types::Serialiser::BooleanBase")
|| sv_isa(obj, "JSON::XS::Boolean")
|| sv_isa(obj,
a::MessagePack::Boolean")
|| sv_isa(obj, "boolean")
|| sv_isa(obj, "Mojo::JSON::_Bool")
)
) {
return ucl_object_frombool( SvTRUE(obj) );
}
else if (
case UCL_BOOLEAN: {
SV* rv = newSV_type(SVt_IV);
sv_setref_iv(rv, "JSON::PP::Boolean", ucl_object_toboolean(obj) ? 1 : 0);
return rv;
}
case
rbose',
handler=>sub {$opts->{verbose}=1},
},
json => {
getopt=>'json',
handler=>sub {$opts->{fmt}='json-pretty'},
},
};
sub _help_cmd {
require Perinci::Cm
name},
meta => $args{meta},
common_opts => $common_opts,
per_arg_json => 1,
);
print $res->[2];
}
sub _run_cmd {
require Perinci::Result::Format;
requ
argv},
meta => $args{meta},
check_required_args => 0,
per_arg_json => 1,
common_opts => $common_opts,
);
if ($res->[0] == 501) {
_CHARACTER_DENIED,
UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE,
UCL_CHARACTER_WHITESPACE|UCL_CHARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_KEY_SEP|UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE
E|UCL_CHARACTER_VALUE_END|UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE,
UCL_CHARACTER_WHITESPACE_UNSAFE,
UCL_CHARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE,
UCL_C
HARACTER_WHITESPACE_UNSAFE|UCL_CHARACTER_VALUE_END|UCL_CHARACTER_JSON_UNSAFE|UCL_CHARACTER_UCL_UNSAFE,
UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED, UCL_CHARACTER_DENIED,
UCL_CHARACTER_DENIED, UCL_CHARA