res->{data};
}
else {
my $data = $res->{data} && $res->{data}->$* ? P->data->from_json( $res->{data} ) : undef;
return res $res->{status}, $data;
}
}
sub _req2 ( $self, $
tent-Type' => 'application/json',
],
data => $data ? P->data->to_json($data) : undef
);
$data = $res->{data} && $res->{data}->$* ? P->data->from_json( $res->{data} ) : undef;
-class, -res;
use Pcore::Util::Scalar qw[is_plain_arrayref];
use Pcore::Util::Data qw[to_uri from_json];
use Pcore::HTTP qw[$UA_CHROME_WINDOWS];
has api_key => (); # direct access to
= $self->{max_threads} && $self->_semaphore->guard;
my $url = 'https://api.majestic.com/api/json?';
if ( $self->{api_key} ) {
$url .= "app_api_key=$self->{api_key}&";
}
elsi
= P->http->get( $url, proxy => $self->{proxy} );
if ($res) {
my $data = eval { from_json $res->{data} };
if ($@) {
$res = res [ 500, 'Error decoding response' ];
t;
use Pcore::API::Chrome::Tab;
use Pcore::Util::Scalar qw[weaken];
use Pcore::Util::Data qw[from_json];
use Pcore::API::Proxy;
use Pcore::API::Proxy::Server;
has bin => ();
has listen => '//
ub tabs ( $self ) {
my $res = P->http->get("http://$self->{listen}->{host_port}/json");
my $tabs = from_json $res->{data};
for my $tab ( $tabs->@* ) {
$tab = bless { chrome => $s
{
my $res = P->http->get( "http://$self->{listen}->{host_port}/json/new?" . ( $url // 'about:blank' ) );
my $data = from_json $res->{data};
my $tab = bless { chrome => $self, id => $data
re::Const;
use common::header;
use Const::Fast qw[const];
use Pcore::Core::Exporter;
use Cpanel::JSON::XS qw[];
# <<<
const our $ANSI => {
RESET => 0,
BOLD => 1,
DARK
our $EMPTY => q[];
const our $SPACE => q[ ];
const our $TRUE => $Cpanel::JSON::XS::true;
const our $FALSE => $Cpanel::JSON::XS::false;
sub TO_BOOL : prototype($) {
return $_[0] ? $TRUE : $FALS
D qw[uuid_v1mc_str uuid_v4_str];
use Pcore::Util::Digest qw[md5_hex];
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Text qw[encode_utf8];
use Time::HiRes qw[];
# NOTE http://habrahabr.ru/post/1
=> $SQLITE_TEXT,
$SQL_FLOAT4 => $SQLITE_REAL,
$SQL_FLOAT8 => $SQLITE_REAL,
$SQL_JSON => $SQLITE_BLOB,
$SQL_INT2 => $SQLITE_INTEGER,
$SQL_INT4 => $SQLITE_INTEGER,
>[0] == $SQL_JSON ) {
$var = to_json $var->[1];
}
else {
$var = $var->[1];
}
}
else {
# transparently encode arrays to JSON
if
-class, -ansi;
use Pcore::API::SMTP;
use Pcore::Handle qw[:TLS_CTX];
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Scalar qw[is_ref];
use Time::HiRes qw[];
with qw[Pcore::Core::Event::Listener
data} ) {
# serialize reference
$body = "\n" . ( is_ref $ev->{data} ? to_json $ev->{data}, readable => 1 : $ev->{data} );
# remove all trailing "\n"
l
}
# load pardeps.json
my $pardeps;
my $pardeps_path = "$self->{dist}->{root}/share/pardeps-$script-@{[$^V->normal]}-$Config{archname}.json";
if ( -f $pardeps_pa
qq[Script "$script" wasn't found.] . $RESET;
next;
}
# add pardeps.json modules, skip eval modules
$profile->{mod}->@{ grep { !/\A[(]eval\s/sm } $pardeps->@* } =
Module::Build
'_build/',
];
const our $FILE => [
# general build
qw[META.json META.yml MYMETA.json MYMETA.yml],
# Module::Build
qw[_build_params Build.PL Build Build.bat],
T8RANGE $SQL_INT8RANGEARRAY $SQL_INTERNAL $SQL_INTERVAL $SQL_INTERVALARRAY $SQL_JSON $SQL_JSONARRAY $SQL_JSONB $SQL_JSONBARRAY $SQL_LANGUAGE_HANDLER $SQL_LINE $SQL_LINEARRAY $SQL_LSEG $SQL_LSEGARRAY $
SQL_VOID $SQL_XID $SQL_XIDARRAY $SQL_XML $SQL_XMLARRAY]],
TYPES => [qw[SQL_BYTEA SQL_JSON SQL_UUID SQL_TEXT]],
QUERY => [qw[SQL SET VALUES ON WHERE IN GROUP_BY HAVING ORDER_B
ARRAY => 1187;
const our $SQL_JSON => 114;
const our $SQL_JSONARRAY => 199;
const our $SQL_JSONB => 3802;
const our $SQL_JSONBARRAY => 3807;
const our
arrayref is_blessed_arrayref];
use Pcore::Util::Digest qw[md5_hex];
use Pcore::Util::Data qw[from_json];
has pool => ( required => 1 ); # InstanceOf ['Pcore::Handle::pgsql']
has is_pgsql => ( 1,
ARRAY ) {
# }
# decode JSON
elsif ( $type == $SQL_JSON ) {
$col = from_json $col;
}
elsif ( looks_
}
elsif ( $param->[0] == $SQL_JSON ) {
$param = $self->encode_json( $param->[1] )->$*;
}
# Maybe [Str]
has permissions => (); # Maybe [HashRef]
*TO_JSON = *TO_CBOR = sub ($self) {
return { $self->%{qw[is_authenticated user_id user_name permission
sub is_server_error ($self) { return substr( $_[0]->{status}, 0, 1 ) >= 5 }
# SERIALIZE
sub TO_JSON ($self) { return { $self->%* } }
sub TO_CBOR ($self) { return { $self->%* } }
1;
__END__
=pod
Pcore::Core::Event::Listener::file;
use Pcore -class, -ansi, -const;
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Scalar qw[is_ref];
use Fcntl qw[:flock];
use IO::File;
use Time::HiRes qw[];
->{data} ) {
# serialize reference
$ev->{text} = is_ref $ev->{data} ? to_json $ev->{data}, readable => 1 : $ev->{data};
# indent
$ev->{text} =~ s/^/$I
e Pcore -class, -ansi, -const;
use Pcore::Util::Text qw[remove_ansi];
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Scalar qw[is_ref];
use Time::HiRes qw[];
with qw[Pcore::Core::Event::Listener
->{data} ) {
# serialize reference
$ev->{text} = is_ref $ev->{data} ? to_json $ev->{data}, readable => 1 : $ev->{data};
# indent
$ev->{text} =~ s/^/$I
package Pcore::App::Controller::API;
use Pcore -role, -const;
use Pcore::Util::Data qw[from_json to_json from_cbor to_cbor];
use Pcore::Util::Scalar qw[is_plain_arrayref];
use Pcore::WebSocket::softv
_TYPE} =~ m[\bapplication/json\b]smi ) {
$msg = eval { from_json $req->{data} };
# content decode error
return 400, q[Error decoding JSON request body] if $@;
cbor $req->{data} };
# content decode error
return 400, q[Error decoding JSON request body] if $@;
$CBOR = 1;
}
# invalid content type
el
y $tree = $self->_gather_files;
$self->_generate_build_pl($tree);
$self->_generate_meta_json($tree);
my $path;
if ($keep) {
$path = P->path( "$self->{dist}->{root}/data/.bu
PL();
BUILD_PL
$tree->add_file( 'Build.PL', \$template );
return;
}
sub _generate_meta_json ( $self, $tree ) {
my $meta = {
abstract => 'unknown',
author => [
_string_hash;
# add META.json
$tree->add_file( 'META.json', \CPAN::Meta->create($meta)->as_string );
# P->file->write_text( "$self->{dist}->{root}/META.json", { crlf => 0 }, CPAN::Meta->
a => $self->{data},
};
$node->write( P->data->to_json($msg) . "\n" );
my $res = $node->read_line;
$res = P->data->from_json($res);
# unable to run elsint
if ( !$res->{statu
};
$node->write( P->data->to_json($msg) . "\n" );
my $res = $node->read_line;
P->text->decode_utf8( $res->$* );
$res = P->data->from_json($res);
# unable to run elsint
};
$node->write( P->data->to_json($msg) . "\n" );
my $res = $node->read_line;
P->text->decode_utf8( $res->$* );
$res = P->data->from_json($res);
if ( !$res->{status} ) {
rayref is_blessed_arrayref];
use Pcore::Util::UUID qw[uuid_v1mc_str];
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Hash::HashArray;
with qw[Pcore::Handle::DBI];
our $EXPORT = {
STATE
turn qq['$var'];
}
elsif ( $var->[0] == $SQL_JSON ) {
# encode and quote
$var = $self->encode_json( $var->[1] );
$var->$* =~ s/'/''/smg;
''/smg;
# quote
return qq['$var'];
}
}
sub encode_json ( $self, $var ) {
# encode
return \to_json $var;
}
sub encode_array ( $self, $var ) {
my @buf;
for my $e
package Pcore::API::Google::FCM;
use Pcore -class, -res;
use Pcore::Util::Data qw[to_json from_json];
extends qw[Pcore::API::Google::OAuth];
has scope => ( 'https://www.googleapis.com/auth/firebase
tion/json',
Authorization => "Bearer $token->{data}->{access_token}",
],
data => to_json $data
);
if ( !$res ) {
my $error = $res->{data} ? from_json $res
s->{reason} = $error->{error}->{message} if $error;
}
else {
$res = res 200, from_json $res->{data};
}
return $res;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Pcore::API
w[];
use Data::MessagePack qw[];
with qw[Pcore::WebSocket::Handle];
# client attributes
has use_json => ();
has token => (); # authentication token, used on client only
has bindings => ();
const our $TX_TYPE_RPC => 'rpc';
my $CBOR = Pcore::Util::Data::get_cbor();
my $JSON = Pcore::Util::Data::get_json( utf8 => 1 );
my $MP = Data::MessagePack->new;
sub rpc_call ( $self, $method, @
xt ( $self, $data_ref ) {
my $msg = eval { $JSON->decode( $data_ref->$* ) };
# unable to decode message
return if $@;
$self->{use_json} //= 1;
$self->_on_message($msg);
ret