-
-
06 Jun 2021 15:49:57 UTC
- Distribution: MooX-Role-JSON_LD
- Module version: 1.0.1
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (989 / 1 / 0)
- Kwalitee
Bus factor: 1- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (8.17KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
- Dependencies
- JSON::MaybeXS
- List::Util
- Moo
- Moose
- Sub::Quote
- Types::Standard
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
MooX::JSON_LD - Extend Moo to provide JSON-LD mark-up for your objects.
SYNOPSIS
# Your Moo (or Moose) Class package My::Moo::Class; use Moo; use MooX::JSON_LD 'Person'; has first_name => ( is => 'ro', # various other properties... json_ld => 1, ); has last_name => ( is => 'ro', # various other properties... json_ld => 1, ); has birth_date => ( is => 'ro', # various other properties... json_ld => 'birthDate', json_ld_serializer => sub { shift->birth_date }, ); # Then, in a program somewhere... use My::Moo::Class; my $obj = My::Moo::Class->new({ first_name => 'David', last_name => 'Bowie', birth_date => '1947-01-08', }); # print a text representation of the JSON-LD print $obj->json_ld; # print the raw data structure for the JSON-LD use Data::Dumper; print Dumper $obj->json_ld_data;
DESCRIPTION
This is a companion module for MooX::Role::JSON_LD. It extends the
has
method to support options to add attributes to thejson_ld_fields
and create thejson_ld_type
.To declare the type, add it as the option when importing the module, e.g.
use MooX::JSON_LD 'Thing';
Moo attributes are extended with the following options:
json_ld
-
has headline => ( is => 'ro', json_ld => 1, );
This adds the "headline" attribute to the
json_ld_fields
.has alt_headline => ( is => 'ro', json_ld => 'alternateHeadline', );
This adds the "alt_headline" attribute to the
json_ld_fields
, with the label "alternateHeadline". json_ld_serializer
-
has birth_date => ( is => 'ro', isa => InstanceOf['DateTime'], json_ld => 'birthDate', json_ld_serializer => sub { shift->birth_date->ymd }, );
This allows you to specify a method for converting the data into an object that JSON can serialize.
AUTHOR
Robert Rothenberg <rrwo@cpan.org>
SEE ALSO
COPYRIGHT AND LICENSE
Copyright (C) 2018, Robert Rothenberg. All Rights Reserved.
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install MooX::Role::JSON_LD, copy and paste the appropriate command in to your terminal.
cpanm MooX::Role::JSON_LD
perl -MCPAN -e shell install MooX::Role::JSON_LD
For more information on module installation, please visit the detailed CPAN module installation guide.