| 1 | # RDF::Trine::Serializer::RDFJSON | ||
| 2 | # ----------------------------------------------------------------------------- | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | RDF::Trine::Serializer::RDFJSON - RDF/JSON Serializer | ||
| 7 | |||
| 8 | =head1 VERSION | ||
| 9 | |||
| 10 | This document describes RDF::Trine::Serializer::RDF/JSON version 1.019 | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | use RDF::Trine::Serializer::RDFJSON; | ||
| 15 | my $serializer = RDF::Trine::Serializer::RDFJSON->new(); | ||
| 16 | |||
| 17 | =head1 DESCRIPTION | ||
| 18 | |||
| 19 | The RDF::Trine::Serializer::Turtle class provides an API for serializing RDF | ||
| 20 | graphs to the RDF/JSON syntax. | ||
| 21 | |||
| 22 | =head1 METHODS | ||
| 23 | |||
| 24 | Beyond the methods documented below, this class inherits methods from the | ||
| 25 | L<RDF::Trine::Serializer> class. | ||
| 26 | |||
| 27 | =over 4 | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | package RDF::Trine::Serializer::RDFJSON; | ||
| 32 | |||
| 33 | 68 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | 68 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | 68 | ▶ | use base qw(RDF::Trine::Serializer); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 36 | |||
| 37 | 68 | ▶ | use URI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 38 | 68 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | 68 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 40 | 68 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 41 | 68 | ▶ | use Scalar::Util qw(blessed); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 42 | |||
| 43 | 68 | ▶ | use RDF::Trine::Node; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | 68 | ▶ | use RDF::Trine::Statement; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 45 | 68 | ▶ | use RDF::Trine::Error qw(:try); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | |||
| 47 | ###################################################################### | ||
| 48 | |||
| 49 | 68 | our ($VERSION); | |
| 50 | 68 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||
| 51 | 68 | $VERSION = '1.019'; | |
| 52 | 68 | $RDF::Trine::Serializer::serializer_names{ 'rdfjson' } = __PACKAGE__; | |
| 53 | 68 | foreach my $type (qw(application/json application/x-rdf+json)) { | |
| 54 | 136 | $RDF::Trine::Serializer::media_types{ $type } = __PACKAGE__; | |
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | ###################################################################### | ||
| 59 | |||
| 60 | =item C<< new >> | ||
| 61 | |||
| 62 | Returns a new serializer object. | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | 2 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||
| 67 | 2 | my $class = shift; | |
| 68 | 2 | my %args = @_; | |
| 69 | 2 | my $self = bless( {}, $class); | |
| 70 | 2 | return $self; | |
| 71 | } | ||
| 72 | |||
| 73 | =item C<< serialize_model_to_file ( $file, $model [,\%json_options] ) >> | ||
| 74 | |||
| 75 | Serializes the C<$model> to RDF/JSON, printing the results to the supplied | ||
| 76 | C<$file> handle. | ||
| 77 | |||
| 78 | C<%json_options> is an options hash suitable for JSON::to_json. | ||
| 79 | |||
| 80 | =cut | ||
| 81 | |||
| 82 | 0 | ▶ | sub serialize_model_to_file { |
|
Subroutine
serialize_model_to_file: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 83 | 0 | my $self = shift; | |
| 84 | 0 | my $file = shift; | |
| 85 | 0 | my $model = shift; | |
| 86 | 0 | my $opts = shift; | |
| 87 | 0 | my $string = to_json($model->as_hashref, $opts); | |
| 88 | 0 | print {$file} $string; | |
| 89 | } | ||
| 90 | |||
| 91 | =item C<< serialize_model_to_string ( $model [,\%json_options] ) >> | ||
| 92 | |||
| 93 | Serializes the C<$model> to RDF/JSON, returning the result as a string. | ||
| 94 | |||
| 95 | C<%json_options> is an options hash suitable for JSON::to_json. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | 1 | ▶ | sub serialize_model_to_string { |
|
Subroutine
serialize_model_to_string: called CC=1 SCAR=0.0
Pod
documented
| |||
| 100 | 1 | my $self = shift; | |
| 101 | 1 | my $model = shift; | |
| 102 | 1 | my $opts = shift; | |
| 103 | 1 | my $string = to_json($model->as_hashref, $opts); | |
| 104 | 1 | return $string; | |
| 105 | } | ||
| 106 | |||
| 107 | 68 | 1; | |
| 108 | |||
| 109 | __END__ | ||