File Coverage

blib/lib/RDF/Trine/Node/Blank.pm
Criterion Covered Total %
statement 57 59 96.6
branch 6 6 100.0
condition 3 3 100.0
subroutine 19 20 95.0
pod 8 8 100.0
total 93 96 96.8


line stmt bran cond sub pod time code
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.017
11              
12             =cut
13              
14             package RDF::Trine::Node::Blank;
15              
16 68     68   390 use strict;
  68         136  
  68         1617  
17 68     68   297 use warnings;
  68         129  
  68         1434  
18 68     68   297 no warnings 'redefine';
  68         142  
  68         1747  
19 68     68   325 use base qw(RDF::Trine::Node);
  68         136  
  68         3963  
20              
21 68     68   401 use Data::Dumper;
  68         138  
  68         2865  
22 68     68   374 use Scalar::Util qw(blessed);
  68         144  
  68         2569  
23 68     68   342 use Carp qw(carp croak confess);
  68         138  
  68         3757  
24              
25             ######################################################################
26              
27             our ($VERSION);
28             BEGIN {
29 68     68   2670 $VERSION = '1.017';
30             }
31              
32             ######################################################################
33              
34 4203     4203   12940 use overload '""' => sub { $_[0]->sse },
35 68     68   367 ;
  68         146  
  68         576  
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             my $COUNTER = 0;
53             sub new {
54 1192     1192 1 4076 my $class = shift;
55 1192         2220 my $name = shift;
56 1192 100       3322 unless (defined($name)) {
57 427         1410 $name = 'r' . time() . 'r' . $COUNTER++;
58             }
59            
60 1192         4419 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 1192         7596 my $r_PN_CHARS = qr"${r_PN_CHARS_U}|[-0-9\x{00B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]";
62 1192         9048 my $r_bnode_id = qr"(?:${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?";
63 1192 100       10285 unless ($name =~ /^${r_bnode_id}$/o) {
64 1         13 throw RDF::Trine::Error::SerializationError -text => "Bad blank node identifier: $name";
65             }
66 1191         3833 return $class->_new( $name );
67             }
68              
69             sub _new {
70 1191     1191   2265 my $class = shift;
71 1191         2098 my $name = shift;
72 1191         7761 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             sub blank_identifier {
82 16784     16784 1 26548 my $self = shift;
83 16784         49242 return $self->[1];
84             }
85              
86             =item C<< value >>
87              
88             Returns the blank identifier.
89              
90             =cut
91              
92             sub value {
93 0     0 1 0 my $self = shift;
94 0         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             sub sse {
104 7403     7403 1 11599 my $self = shift;
105 7403         14261 my $id = $self->blank_identifier;
106 7403         24670 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             sub as_ntriples {
116 37     37 1 82 my $self = shift;
117 37         113 my $id = $self->blank_identifier;
118 37         195 return qq(_:${id});
119             }
120              
121             =item C<< as_string >>
122              
123             Returns a string representation of the node.
124              
125             =cut
126              
127             sub as_string {
128 5955     5955 1 9864 my $self = shift;
129 5955         12064 return '(' . $self->blank_identifier . ')';
130             }
131              
132             =item C<< type >>
133              
134             Returns the type string of this node.
135              
136             =cut
137              
138             sub type {
139 2481     2481 1 5577 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             sub equal {
149 314     314 1 568 my $self = shift;
150 314         498 my $node = shift;
151 314 100 100     2633 return 0 unless (blessed($node) and $node->isa('RDF::Trine::Node::Blank'));
152 194         530 return ($self->blank_identifier eq $node->blank_identifier);
153             }
154              
155             # called to compare two nodes of the same type
156             sub _compare {
157 503     503   793 my $a = shift;
158 503         757 my $b = shift;
159 503         942 return ($a->blank_identifier cmp $b->blank_identifier);
160             }
161              
162             1;
163              
164             __END__
165              
166             =back
167              
168             =head1 BUGS
169              
170             Please report any bugs or feature requests to through the GitHub web interface
171             at L<https://github.com/kasei/perlrdf/issues>.
172              
173             =head1 AUTHOR
174              
175             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
176              
177             =head1 COPYRIGHT
178              
179             Copyright (c) 2006-2012 Gregory Todd Williams. This
180             program is free software; you can redistribute it and/or modify it under
181             the same terms as Perl itself.
182              
183             =cut