package Net::Fluidinfo::JSON;
use Moose;
use JSON::XS;
has json => (
is => 'ro',
isa => 'JSON::XS',
default => sub { JSON::XS->new->utf8->allow_nonref },
handles => [qw(enco
ue::Set;
use Moose;
extends 'Net::Fluidinfo::Value::Native';
sub to_json {
my $self = shift;
my @strings = map $self->json->encode("$_"), @{$self->value};
'[' . join(',', @strings) . ']'
_about ? $self->json->encode({about => $self->about}) : undef;
$self->fin->post(
path => $self->abs_path('objects'),
headers => $self->fin->headers_for_json,
paylo
payload,
on_success => sub {
my $response = shift;
my $h = $self->json->decode($response->content);
$self->_set_id($h->{id});
# Unset tag paths
ts,
headers => $fin->accept_header_for_json,
on_success => sub {
my $response = shift;
my $h = $class->json->decode($response->content);
my $o =
:Native->is_mime_type($mime_type)) {
Net::Fluidinfo::Value::Native->new_from_fin_type_and_json($fin_type, $content);
} else {
# instead of ordinary use(), to play nice with inherit
package Net::Fluidinfo::Base;
use Moose;
use JSON::XS;
use Carp;
use MooseX::ClassAttribute;
class_has json => (is => 'ro', default => sub { JSON::XS->new->utf8->allow_nonref });
has fin => (is =>
ub true {
shift->as_json_boolean(1);
}
sub false {
shift->as_json_boolean(0);
}
sub as_json_boolean {
my ($receiver, $flag) = @_;
$flag ? JSON::XS::true : JSON::XS::false;
}
sub get
my $self = shift;
my $payload = $self->json->encode({
description => $self->description,
indexed => $self->as_json_boolean($self->indexed),
name => $se
ders => $self->fin->headers_for_json,
payload => $payload,
on_success => sub {
my $response = shift;
my $h = $self->json->decode($response->content);
ts,
headers => $fin->accept_header_for_json,
on_success => sub {
my $response = shift;
my $h = $class->json->decode($response->content);
my $t =
to set description and path of self.
sub create {
my $self = shift;
my $payload = $self->json->encode({description => $self->description, name => $self->name});
$self->fin->post(
ders => $self->fin->headers_for_json,
payload => $payload,
on_success => sub {
my $response = shift;
my $h = $self->json->decode($response->content);
ts,
headers => $fin->accept_header_for_json,
on_success => sub {
my $response = shift;
my $h = $class->json->decode($response->content);
my $ns =
},
headers => $fin->accept_header_for_json,
on_success => sub {
my $response = shift;
my $h = $class->json->decode($response->content);
$class->
h
);
}
);
}
sub update {
my $self = shift;
my $payload = $self->json->encode({policy => $self->policy, exceptions => $self->exceptions});
$self->fin->put(
path),
query => { action => $self->action },
headers => $self->fin->headers_for_json,
payload => $payload
);
}
no Moose;
no MooseX::ClassAttribute;
__PACKAGE__->meta->ma
e),
headers => $fin->accept_header_for_json,
on_success => sub {
my $response = shift;
my $h = $class->json->decode($response->content);
my $user
se Moose;
extends 'Net::Fluidinfo::Value::Native';
sub to_json {
my $self = shift;
no warnings; # value may be undef
$self->json->encode('' . $self->value);
}
no Moose;
__PACKAGE__->meta
ckage Net::Fluidinfo::Value::Boolean;
use Moose;
extends 'Net::Fluidinfo::Value::Native';
sub to_json {
my $self = shift;
$self->value ? 'true' : 'false';
}
no Moose;
__PACKAGE__->meta->make
;
use Moose;
extends 'Net::Fluidinfo::Value::Native';
# A Perl integer is a JSON integer. Sanitize with int().
sub to_json {
my $self = shift;
no warnings; # the value may not be an integer i
nteger,
# and it won't pick it as float unless you serialise it explicitly as such: "5.0".
sub to_json {
my $self = shift;
no warnings; # value may not be a number
my $float = 0 + $self->
package Net::Fluidinfo::Value::Null;
use Moose;
extends 'Net::Fluidinfo::Value::Native';
sub value {
undef;
}
sub to_json {
'null';
}
no Moose;
__PACKAGE__->meta->make_immutable;
1;
Strings;
use Moose;
extends 'Net::Fluidinfo::Value::Native';
sub to_json {
my $self = shift;
my @strings = map $self->json->encode("$_"), @{$self->value};
'[' . join(',', @strings) . ']';
luidinfo::Value';
use Carp;
use Net::Fluidinfo::JSON;
use MooseX::ClassAttribute;
class_has json => (is => 'ro', default => sub { Net::Fluidinfo::JSON->new });
# In the future more serialisation for
ddb.value+json';
sub mime_type {
$MIME_TYPE;
}
sub is_mime_type {
my ($class, $mime_type) = @_;
defined $mime_type && $mime_type eq $MIME_TYPE;
}
sub new_from_fin_type_and_json {
my
($class, $fin_type, $json) = @_;
my $native_class = $class->class_for_fin_type($fin_type);
$native_class->new(value => $class->json->decode($json));
}
# Fluidinfo types of native values are
= 'fluiddb.fluidinfo.com';
our $SANDBOX_HOST = 'sandbox.fluidinfo.com';
our $JSON_CONTENT_TYPE = 'application/json';
has protocol => (is => 'rw', isa => 'Str', default => $DEFAULT_PROTOCOL);
has
s_for_json {
return {
'Accept' => $JSON_CONTENT_TYPE,
'Content-Type' => $JSON_CONTENT_TYPE
};
}
sub accept_header_for_json {
return {
'Accept' => $JSON_CONTE
NT_TYPE
}
}
sub content_type_header_for_json {
return {
'Content-Type' => $JSON_CONTENT_TYPE
}
}
#
# -- Convenience shortcuts ----------------------------------------------------