RDF/Trine/Node/Blank.pm

filter: Statementstmt 96.7% 60 / 62 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 95.0% 19 / 20 Podpod 100% 8 / 8 totaltotal 97.0% 98 / 101 CC 5 SCAR 4.3
CC
5
Cov
97%
new
3.0
equal
3.0
value
2.0
CRAP 1.5
« RDF/Trine/Model/Union.pm ↑ Summary RDF/Trine.pm »
1 # RDF::Trine::Node::Blank
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine::Node::Blank - RDF Node class for blank nodes
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine::Node::Blank version 1.019
11  
12 =cut
13  
14 package RDF::Trine::Node::Blank;
15  
16 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 68 ▶use base qw(RDF::Trine::Node);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 68 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 68 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 68 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ######################################################################
26  
27 68 our ($VERSION);
28 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 68 $VERSION = '1.019';
30 }
31  
32 ######################################################################
33  
34 1285 ▶use overload '""' => sub { $_[0]->sse },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
35 68 ;
36  
37 =head1 METHODS
38  
39 Beyond the methods documented below, this class inherits methods from the
40 L<RDF::Trine::Node> class.
41  
42 =over 4
43  
44 =cut
45  
46 =item C<new ( $name )>
47  
48 Returns a new Blank structure.
49  
50 =cut
51  
52 68 my $COUNTER = 0;
53 1188 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
54 1188 my $class = shift;
55 1188 my $name = shift;
56 1188 ▶ unless (defined($name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 428 760 1188
57 428 $name = 'r' . time() . 'r' . $COUNTER++;
58 }
59
60 1188 my $r_PN_CHARS_U = qr/[_A-Za-z_\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}]/;
61 1188 my $r_PN_CHARS = qr"${r_PN_CHARS_U}|[-0-9\x{00B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]";
62 1188 my $r_bnode_id = qr"(?:${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?";
63 1188 ▶ unless ($name =~ /^${r_bnode_id}$/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /^$r_bnode_id$/o) 1 1187 1188
64 1 throw RDF::Trine::Error::SerializationError -text => "Bad blank node identifier: $name";
65 }
66 1187 return $class->_new( $name );
67 }
68  
69 1187 ▶sub _new {
Subroutine _new: called CC=1 SCAR=0.0
70 1187 my $class = shift;
71 1187 my $name = shift;
72 1187 return bless( [ 'BLANK', $name ], $class );
73 }
74  
75 =item C<< blank_identifier >>
76  
77 Returns the identifier of the blank node.
78  
79 =cut
80  
81 13117 ▶sub blank_identifier {
Subroutine blank_identifier: called CC=1 SCAR=0.0
Pod documented
82 13117 my $self = shift;
83 13117 return $self->[1];
84 }
85  
86 =item C<< value >>
87  
88 Returns the blank identifier.
89  
90 =cut
91  
92 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
93 0 my $self = shift;
94 0 return $self->blank_identifier;
95 }
96  
97 =item C<< sse >>
98  
99 Returns the SSE string for this blank node.
100  
101 =cut
102  
103 4481 ▶sub sse {
Subroutine sse: called CC=1 SCAR=0.0
Pod documented
104 4481 my $self = shift;
105 4481 my $id = $self->blank_identifier;
106 4481 return qq(_:${id});
107 }
108  
109 =item C<< as_ntriples >>
110  
111 Returns the node in a string form suitable for NTriples serialization.
112  
113 =cut
114  
115 37 ▶sub as_ntriples {
Subroutine as_ntriples: called CC=1 SCAR=0.0
Pod documented
116 37 my $self = shift;
117 37 my $id = $self->blank_identifier;
118 37 return qq(_:${id});
119 }
120  
121 =item C<< as_string >>
122  
123 Returns a string representation of the node.
124  
125 =cut
126  
127 5214 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
128 5214 my $self = shift;
129 5214 return '(' . $self->blank_identifier . ')';
130 }
131  
132 =item C<< type >>
133  
134 Returns the type string of this node.
135  
136 =cut
137  
138 2479 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
139 2479 return 'BLANK';
140 }
141  
142 =item C<< equal ( $node ) >>
143  
144 Returns true if the two nodes are equal, false otherwise.
145  
146 =cut
147  
148 314 ▶sub equal {
Subroutine equal: called CC=3 SCAR=11.0
Pod documented
149 314 my $self = shift;
150 314 my $node = shift;
151 314 ▶ return 0 unless (blessed($node) and $node->isa('RDF::Trine::Node::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($node) and $node->isa("RDF::Trine::Node::Blank") 120 194 314
Condition100%3/3
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Blank")
!ll&&!rl&&r
2694194
MC/DC100%2/2
builtin::blessed($node) and $node->isa("RDF::Trine::Node::Blank")
builtin::blessed($node) $node->isa("RDF::Trine::Node::Blank")
Truth table100%3/3
A and B
A= builtin::blessed($node)B= $node->isa("RDF::Trine::Node::Blank")
ABresult
0X0
100
111
152 194 return ($self->blank_identifier eq $node->blank_identifier);
153 }
154  
155 # called to compare two nodes of the same type
156 503 ▶sub _compare {
Subroutine _compare: called CC=1 SCAR=0.0
157 503 my $a = shift;
158 503 my $b = shift;
159 503 return ($a->blank_identifier cmp $b->blank_identifier);
160 }
161  
162 68 1;
163  
164 __END__
« RDF/Trine/Model/Union.pm ↑ Summary RDF/Trine.pm »