kage JSON::API::v1;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
use List::Util qw(uniq);
our @CARP_NOT = qw(Class::MOP::Method::Wrapped);
# ABSTRACT: A JSON API
object according to jsonapi.org v1 specification
has data => (
is => 'ro',
isa => 'ArrayRef[JSON::API::v1::Resource]',
traits => ['Array'],
lazy => 1,
default
'ArrayRef[JSON::API::v1::Error]',
traits => ['Array'],
lazy => 1,
default => sub { [] },
handles => { add_error => 'push', has_errors => 'count' },
);
has jsonapi => (
package JSON::API::v1::Roles::TO_JSON;
our $VERSION = '0.002';
use Moose::Role;
use namespace::autoclean;
# ABSTRACT: An interface for Objects to adhere to
requires qw(
TO_JSON
);
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::Roles::TO_JSON - An interface for Objects to adhere to
=head1 VERSION
version 0.002
=head1 SYNOPSIS
=head1 DESCRIPTION
This role implements an
which consumers must adhere to. It defines
several methods that L<JSON::API::v1> namespaced objects must implement
to support the JSON API v1 specifications.
=head1 AUTHOR
Wesley Schwengle
=head1 L
use utf8;
package JSON::API::v1::MetaObject;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
# ABSTRACT: A JSON API Meta object according to jsonapi v1 specification
has members => (
b TO_JSON {
my $self = shift;
my %rv;
foreach ($self->get_member_names) {
$rv{$_} = $self->get_member($_);
}
return \%rv;
}
with qw(
JSON::API::v1::Roles::TO_JSON
);
ta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::MetaObject - A JSON API Meta object according to jsonapi v1 specification
=head1 VERSION
version 0.002
=head1 SYNOPS
use utf8;
package JSON::API::v1::Links;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
use MooseX::Types::URI qw(Uri);
# ABSTRACT: A JSON API Links object
has uri
1,
);
has related => (
is => 'ro',
isa => 'JSON::API::v1::Links',
predicate => 'has_related',
);
sub TO_JSON {
my $self = shift;
if (!$self->has_uri && !$self->has_
qw(
JSON::API::v1::Roles::TO_JSON
JSON::API::v1::Roles::MetaObject
);
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::Links - A JSON API Link
use utf8;
package JSON::API::v1::JSONAPI;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
# ABSTRACT: A JSON API jsonapi object
sub TO_JSON {
my $self = shift;
JSON::API::v1::Roles::TO_JSON
JSON::API::v1::Roles::MetaObject
);
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::JSONAPI - A JSON API jsonapi
head1 VERSION
version 0.002
=head1 SYNOPSIS
use JSON::API::v1::JSONAPI;
my $object = JSON::API::v1::JSONAPI->new(
meta => JSON::API::v1::MetaObject->new(),
);
=head1 DESCRIPTIO
use utf8;
package JSON::API::v1::Error;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
# ABSTRACT: A JSON API object according to jsonapi.org v1 specification
has id => (
is
=> (
is => 'ro',
isa => 'Defined',
predicate => 'has_source',
);
sub TO_JSON {
my $self = shift;
my %rv;
foreach (qw(id status code title detail source links)) {
(
JSON::API::v1::Roles::TO_JSON
JSON::API::v1::Roles::MetaObject
JSON::API::v1::Roles::Links
);
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API
e utf8;
package JSON::API::v1::Attribute;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
use List::Util qw(any);
our @CARP_NOT;
# ABSTRACT: A JSON API Attribute ob
ject according to jsonapi v1 specification
has attributes => (
is => 'ro',
isa => 'HashRef',
traits => ['Hash'],
lazy => 1,
default => sub { {} },
handles => {
clear_attribute => 'delete',
get_attribute_names => 'keys',
},
);
sub TO_JSON {
my $self = shift;
my %rv;
foreach ($self->get_attribute_names) {
$rv{$_} =
package JSON::API::v1::Roles::MetaObject;
our $VERSION = '0.002';
use Moose::Role;
use namespace::autoclean;
# ABSTRACT: An role that implements the default meta object
has meta_object => (
is
'has_meta_object',
init_arg => 'meta',
);
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::Roles::MetaObject - An role that implements the default meta object
=head1 VERSION
ve
package JSON::API::v1::Roles::Links;
our $VERSION = '0.002';
use Moose::Role;
use namespace::autoclean;
# ABSTRACT: An role that implements the default links object
has links => (
is => '
ro',
isa => 'JSON::API::v1::Links',
predicate => 'has_links',
);
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::Roles::Links - An role that implements the default links
utf8;
package JSON::API::v1::Relationship;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
use List::Util qw(any);
our @CARP_NOT;
# ABSTRACT: A JSON API Relationsh
ip object according to jsonapi v1 specification
has data => (
is => 'ro',
isa => 'Defined',
predicate => 'has_data',
);
sub TO_JSON {
my $self = shift;
if (!$self->
(
JSON::API::v1::Roles::TO_JSON
JSON::API::v1::Roles::Links
JSON::API::v1::Roles::MetaObject
);
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API
use utf8;
package JSON::API::v1::Resource;
our $VERSION = '0.002';
use Moose;
use namespace::autoclean;
use Carp qw(croak);
# ABSTRACT: A JSON API Resource object
has id => (
is => 'ro',
is => 'ro',
isa => 'Defined',
predicate => 'has_relationships',
);
sub TO_JSON {
my $self = shift;
if ($self->has_id && $self->has_type) {
return {
qw(
JSON::API::v1::Roles::TO_JSON
JSON::API::v1::Roles::MetaObject
);
__PACKAGE__->meta->make_immutable;
__END__
=pod
=encoding UTF-8
=head1 NAME
JSON::API::v1::Resource - A JSON API Res