RDF/Trine/Serializer/RDFPatch.pm

filter: Statementstmt 61.2% 57 / 93 Branchbran 41.6% 5 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 15 / 18 Podpod 100% 5 / 5 totaltotal 62.4% 83 / 133 CC 9 SCAR 10.5
CC
9
Cov
58%
serialize_model_to_file
6.0
serialize_model_to_string
6.0
serialize_iterator_to_file
6.0
CRAP 2.8
« RDF/Trine/Parser/NQuads.pm ↑ Summary RDF/Trine/Iterator/Graph/Materialized.pm »
1 # RDF::Trine::Serializer::RDFPatch
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine::Serializer::RDFPatch - RDF-Patch Serializer
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine::Serializer::RDFPatch version 1.019
11  
12 =head1 SYNOPSIS
13  
14 use RDF::Trine::Serializer::RDFPatch;
15 my $serializer = RDF::Trine::Serializer::RDFPatch->new();
16  
17 =head1 DESCRIPTION
18  
19 The RDF::Trine::Serializer::RDFPatch class provides an API for serializing RDF
20 graphs to the RDF-Patch 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::RDFPatch;
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 Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 68 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 68 ▶use List::Util qw(min);
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 68 ▶use RDF::Trine::Exporter::RDFPatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 ######################################################################
49  
50 68 our ($VERSION);
51 68 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
52 68 $VERSION = '1.019';
53 68 $RDF::Trine::Serializer::serializer_names{ 'rdfpatch' } = __PACKAGE__;
54 # $RDF::Trine::Serializer::format_uris{ 'http://www.w3.org/ns/formats/RDF-Patch' } = __PACKAGE__;
55 68 foreach my $type (qw(application/rdf-patch)) {
56 68 $RDF::Trine::Serializer::media_types{ $type } = __PACKAGE__;
57 }
58 }
59  
60 ######################################################################
61  
62 =item C<< new >>
63  
64 Returns a new RDF-Patch serializer object.
65  
66 =cut
67  
68 2 ▶sub new {
Subroutine new: called CC=4 SCAR=15.0
Pod documented
69 2 my $class = shift;
70 2 my %args;
71 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
72 1 ▶ if (scalar(@_) == 1 and reftype($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and reftype($_[0]) eq 'HASH') { } 0 1 1
Condition33%1/3
scalar @_ == 1 and reftype($_[0]) eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
scalar @_ == 1 and reftype($_[0]) eq "HASH"
scalar @_ == 1 reftype($_[0]) eq "HASH"
Truth table33%1/3
A and B
A= scalar @_ == 1B= reftype($_[0]) eq "HASH"
ABresult
0X0
100
111
73 0 my $ns = shift;
74 0 %args = ( namespaces => $ns );
75 } else {
76 1 %args = @_;
77 }
78 }
79 2 my $self = bless({ args => [ %args ] }, $class);
80 2 return $self;
81 }
82  
83 =item C<< serialize_model_to_file ( $fh, $model ) >>
84  
85 Serializes the C<$model> to RDF-Patch, printing the results to the supplied
86 filehandle C<<$fh>>.
87  
88 =cut
89  
90 0 ▶sub serialize_model_to_file {
Subroutine serialize_model_to_file: not called CC=2 SCAR=17.9
Pod documented
91 0 my $self = shift;
92 0 my $fh = shift;
93 0 my $model = shift;
94
95 0 my $sink = RDF::Trine::Serializer::FileSink->new( $fh );
96 0 my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink );
97
98 0 my $st = RDF::Trine::Statement->new( map { RDF::Trine::Node::Variable->new($_) } qw(s p o) );
99 0 my $pat = RDF::Trine::Pattern->new( $st );
100 0 my $stream = $model->get_pattern( $pat, undef, orderby => [ qw(s ASC p ASC o ASC) ] );
101 0 my $iter = $stream->as_statements( qw(s p o) );
102 0 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
103 0 $e->add( $st );
104 }
105 }
106  
107 =item C<< serialize_model_to_string ( $model ) >>
108  
109 Serializes the C<$model> to RDF-Patch, returning the result as a string.
110  
111 =cut
112  
113 0 ▶sub serialize_model_to_string {
Subroutine serialize_model_to_string: not called CC=2 SCAR=17.9
Pod documented
114 0 my $self = shift;
115 0 my $model = shift;
116  
117 0 my $sink = RDF::Trine::Serializer::StringSink->new();
118 0 my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink );
119  
120 0 my $st = RDF::Trine::Statement->new( map { RDF::Trine::Node::Variable->new($_) } qw(s p o) );
121 0 my $pat = RDF::Trine::Pattern->new( $st );
122 0 my $stream = $model->get_pattern( $pat, undef, orderby => [ qw(s ASC p ASC o ASC) ] );
123 0 my $iter = $stream->as_statements( qw(s p o) );
124 0 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
125 0 $e->add( $st );
126 }
127
128 0 return $sink->string;
129 }
130  
131 =item C<< serialize_iterator_to_file ( $file, $iter ) >>
132  
133 Serializes the iterator to RDF-Patch, printing the results to the supplied
134 filehandle C<<$fh>>.
135  
136 =cut
137  
138 0 ▶sub serialize_iterator_to_file {
Subroutine serialize_iterator_to_file: not called CC=2 SCAR=17.9
Pod documented
139 0 my $self = shift;
140 0 my $fh = shift;
141 0 my $iter = shift;
142
143 0 my $sink = RDF::Trine::Serializer::FileSink->new( $fh );
144 0 my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink );
145
146 0 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 0 0 0
147 0 $e->add( $st );
148 }
149 }
150  
151 =item C<< serialize_iterator_to_string ( $iter ) >>
152  
153 Serializes the iterator to RDF-Patch, returning the result as a string.
154  
155 =cut
156  
157 2 ▶sub serialize_iterator_to_string {
Subroutine serialize_iterator_to_string: called CC=2 SCAR=6.9
Pod documented
158 2 my $self = shift;
159 2 my $iter = shift;
160  
161 2 my $sink = RDF::Trine::Serializer::StringSink->new();
162 2 my $e = RDF::Trine::Exporter::RDFPatch->new( @{ $self->{args} }, sink => $sink );
163
164 2 ▶ while (my $st = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $st = $iter->next) 8 2 10
165 8 $e->add( $st );
166 }
167
168 2 return $sink->string;
169 }
170  
171 68 1;
172  
173 __END__
« RDF/Trine/Parser/NQuads.pm ↑ Summary RDF/Trine/Iterator/Graph/Materialized.pm »