Plugin::HTMX;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::ByteStream;
use Mojo::JSON qw(encode_json decode_json);
use Mojo::Util qw(xml_escape);
our $VERSION = '1.03';
my @HX_RESWAPS = (qw[
r') });
$app->helper(
'htmx.req.triggering_event' => sub {
eval { decode_json(_header(shift, 'Triggering-Event')) } || {};
}
);
$app->helper(
'htmx.re
return undef unless $location;
if (ref $location eq 'HASH') {
$location = encode_json($location);
}
return $c->res->headers->header('HX-Location' => $location);
}
sub _res_
) = @_;
return Business::GoCardless::Webhook->new(
client => $self->client,
json => $data,
);
}
sub _generic_find_obj {
my ( $self,$id,$class,$sub_key ) = @_;
$cla
ut
use strict;
use warnings;
use Moo;
use JSON ();
use Carp qw/ cluck /;
with 'Throwable';
=head1 ATTRIBUTES
=head2 message
The error message, if JSON is passed this will be coerced to a string.
code.
=head2 response
The error response, generally the HTTP response.
=cut
# plain string or JSON
has message => (
is => 'ro',
required => 1,
coerce => sub {
my ( $mes
# defensive decoding
eval { $message = JSON->new->decode( $message ) };
$@ && do { return "Failed to parse JSON response ($message): $@"; };
if ( ref( $mess
# the app is using a serializer and we were sent a blob of JSON, they could
# have come from that JSON, and thus could be hashrefs (JSON SQL injection)
# - for database providers, feeding a c
GoCardless::Utils';
use JSON ();
use Business::GoCardless::Client;
use Business::GoCardless::Exception;
use Business::GoCardless::Webhook::Event;
=head1 ATTRIBUTES
json
signature
has_le
}
=head2 json
Allows you to set the json data sent to you in the webhook:
$Webhook->json( $json_data )
Will throw a L<Business::GoCardless::Exception> exception if the json fails to
parse
has json => (
is => 'rw',
required => 1,
trigger => sub {
my ( $self,$json ) = @_;
# defensive decoding
my $params;
eval { $params = JSON->new->decode( $json ) };
;
}
=head2 Another filehandle example - Working with Net::FTP
Say you want to read all the json files from ftp://ftp.perl.org/pub/CPAN/
using Net::FTP and write them directly
to a zip archive w
ings;
use Net::FTP;
use Archive::Zip::SimpleZip qw($SimpleZipError);
my $zipFile = 'json.zip';
my $host = 'ftp.perl.org';
my $path = '/pub/CPAN';
my $zip = Archive::Zip::Sim
my @files = $ftp->ls()
or die "Cannot ls", $ftp->message;
for my $file ( grep { /json$/ } @files)
{
print " Adding $file\n" ;
my $zipMember = $zip->openMember(Nam
e project
use version 0.77; our $VERSION = qv(v0.6.1);
use strict;
use warnings;
use JSON::PP 2.0104 qw(decode_json);
use File::Path 2.07 qw(make_path remove_tree);
use Cwd qw(abs_path getcwd);
use Da
ure qw(gnu_getopt);
use constant {
START_WD => getcwd(),
PROJECT_FILE => 'apperl-project.json',
};
use constant {
PROJECT_TMP_DIR => (START_WD.'/.apperl'),
};
use constant {
# DEFDATA
rl'
: PROJECT_TMP_DIR.'/site',
PROJECT_TMP_CONFIG_FILE => (PROJECT_TMP_DIR.'/user-project.json'),
};
use constant {
SITE_CONFIG_DIR => ($ENV{XDG_CONFIG_HOME} // (DEFDATAROOT.'/.config'))
$ catmandu import JSON to ElasticSearch --bag catmandu < data.json
# Export data from ElasticSearch
$ catmandu export ElasticSearch --bag catmandu to JSON > data.json
# Export only o
fault Search::Elasticsearch client version
$ catmandu import JSON to ElasticSearch --bag catmandu --client '5_0::Direct' < data.json
# From Perl
use Catmandu;
my $store = Catmandu->
ore, C<search> in this case:
$ catmandu import JSON to search --bag mybag < data.json
$ catmandu export search --bag mybag to JSON > data.json
=head1 CQL MAPPING
Catmandu::Store::ElasticSearc
return $self->res->json("/message") || $self->error || $self->res->message
}
sub apicode {
my $self = shift;
return $self->res->json("/code") || ($self->res->json("/status")
? 'E
_TYPE_JSON, # "*/*"
}
);
return 0 unless $status;
# Check API status
return 0 unless $self->res->json("/status");
# Check code
my $error_code = $self->res->json("/cod
self->request(GET => $self->str2url($url),
{ # Headers
Accept => CONTENT_TYPE_JSON, # "*/*"
}
);
}
sub api_data { # /api
my $self = shift;
my $url = shift || ''
self->str2url("v1/authn"),
{ # Headers
Accept => CONTENT_TYPE_JSON, # "*/*"
},
json => {%data},
);
}
sub authz {
my $self = shift;
my $method = shift //
self->str2url("v1/authz"),
{ # Headers
Accept => CONTENT_TYPE_JSON, # "*/*"
},
json => {%data},
);
}
sub pubkey {
my $self = shift;
my $set = shift || 0
Accept => CONTENT_TYPE_JSON, # "*/*"
},
);
return 0 unless $status;
# Get public_key
my $public_key = $self->res->json("/public_key") if $self->res->json("/status");
$self
> $self->str2url("file"), # e.g.: api/file
{ # Headers
Accept => CONTENT_TYPE_JSON, # "*/*"
}
);
}
sub download {
my $self = shift;
my $rfile = shift; # Remote
debug "before_authenticate_user", to_json( shift, { canonical => 1 } );
};
hook after_authenticate_user => sub {
debug "after_authenticate_user", to_json( shift, { canonical => 1 } );
};
hook b
efore_create_user => sub {
debug "before_create_user", to_json( shift, { canonical => 1 } );
};
hook after_create_user => sub {
my ( $username, $user, $errors ) = @_;
my $ret = $user ? 1 :
g;
use Catmandu::Sane;
our $VERSION = '1.0204';
use Catmandu::Hits;
use Cpanel::JSON::XS qw(encode_json decode_json);
use Catmandu::Store::ElasticSearch::Searcher;
use Catmandu::Store::ElasticSearc
throw(encode_json($res));
};
}
if (is_string($cb) && $cb eq 'log') {
return sub {
my ($action, $res, $i) = @_;
$self->log->error(encode_json($res));
on_success} = sub {
my ($action, $res, $i) = @_;
$self->log->debug(encode_json($res));
};
}
$self->store->es->bulk_helper(%args);
}
sub generator {
my ($se
Bag;
use Catmandu::Sane;
our $VERSION = '0.03';
use Catmandu::Hits;
use Cpanel::JSON::XS qw(encode_json decode_json);
use Catmandu::Store::OpenSearch::Searcher;
use Catmandu::Store::OpenSearch::CQL
::Error->throw("unable to create index: ".encode_json($res->error));
} else {
Catmandu::Error->throw("unable to create index: ".encode_json($res->error));
}
1;
}
sub default_buff
throw(encode_json($res));
};
}
if (is_string($cb) && $cb eq 'log') {
return sub {
my ($action, $res, $i) = @_;
$self->log->error(encode_json($res));
rs of this plugin are allows get access to configuration parameters by path-pointers.
See L<Mojo::JSON::Pointer> and L<RFC 6901|https://tools.ietf.org/html/rfc6901>
=over 8
=item conf-E<gt>get
se Mojo::Base 'Mojolicious::Plugin';
use Config::General qw//;
use Mojo::File qw/path/;
use Mojo::JSON::Pointer qw//;
use constant DEFAULT_CG_OPTS => {
'-ApacheCompatible' => 1, # Makes possible
r false values, will be normalised to 1 or 0 respectively
};
has 'config_pointer' => sub { Mojo::JSON::Pointer->new };
sub register {
my ($self, $app, $args) = @_;
# NoLoad
my $noload =
hift;
my @json_lines = path($file)->lines;
my %stats;
# The file is line-delimited JSON, where each line is a separate
# JSON object, so we need to read each line as JSON separately.
cessed.
my $metadata_json = shift @json_lines;
%stats = %{ JSON::from_json($metadata_json) };
for my $line (@json_lines) {
my $line_data = JSON::from_json($line);
$stats{q
uery</th>
<th>Took</th>
<th>Stack</th>
</tr>
HTML
for my $json_line ($profile_path->lines) {
my $data = JSON::from_json($json_line);
# Find first useful line of the stack (knowin
rch
$ catmandu import JSON to OpenSearch --bag catmandu < data.json
# Export data from OpenSearch
$ catmandu export OpenSearch --bag catmandu to JSON > data.json
# Export only one re
ore, C<search> in this case:
$ catmandu import JSON to search --bag mybag < data.json
$ catmandu export search --bag mybag to JSON > data.json
=head1 CQL MAPPING
Catmandu::Store::OpenSearch s
C<search> in this case:
$ catmandu export search --bag book -q 'title any blablabla' to JSON > data.json
=head1 COMPATIBILITY
This perl client works with the current Opensearch server 7.* at the
package Dancer2::Session::DBI;
use 5.006;
use strict;
use warnings;
use Moo;
use JSON;
use DBI;
use Carp qw( carp croak );
=encoding utf8
=head1 NAME
Dancer2::Session::DBI - DBI based session eng
the session and storing it
in a database via L<DBI>. The only supported serialization method is L<JSON>.
This was, so far, only tested with PostgreSQL but should in theory work
with MySQL and SQLite
re id=?");
$sth->execute($session_id);
my ($json) = $sth->fetchrow_array();
# Bail early if we know we have no session data at all
if (!defined $json) {
carp("Could not retrieve session ID: $se
new filehandle at the beginning of each request.
use DBI::Log timing => 1, trace => 1, format => 'json', file => '/dev/null';
# Ick - find a better way to pass this around than a global var!
my $dbi
open $path to write - $!");
# Write our metadata to the log first
print {$dbilog_fh} JSON::to_json(
{
logged_by => __PACKAGE__ . "/$VERSION",
method => $c
int keeping the log, so we should delete it.
seek $DBI::Log::opts{fh}, 0, 0;
my $metadata_json = <$DBI::Log::opts{fh}>;
my $first_query = <$DBI::Log::opts{fh}>;
if (!$first_query) {
se warnings;
use utf8;
our $VERSION = '1.0';
use Data::Dumper;
use WWW::Mechanize;
use JSON::XS qw(decode_json);
sub new($proto, %config) {
my $class = ref($proto) || $proto;
my $self = bl
my $url = "http://ip-api.com/json/" . $ip;
my $content = $self->_fetchURL($url);
my $ok = 0;
my $decoded;
eval {
$decoded = decode_json($content);
$ok = 1;
}
if(!$ok || !defined($decoded)) {
$self->_debuglog("Failed to decode response. Not a JSON document?");
$self->_debuglog(Dumper($decoded));
return;
}
#$self->_debu