File Coverage

blib/lib/RDF/Query/Node/Blank.pm
Criterion Covered Total %
statement 54 58 93.1
branch 9 12 75.0
condition n/a
subroutine 18 20 90.0
pod 4 4 100.0
total 85 94 90.4


line stmt bran cond sub pod time code
1             # RDF::Query::Node::Blank
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Node::Blank - RDF Node class for blank nodes
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Node::Blank version 2.918.
11              
12             =head1 METHODS
13              
14             Beyond the methods documented below, this class inherits methods from the
15             L<RDF::Query::Node> and L<RDF::Trine::Node::Blank> classes.
16              
17             =over 4
18              
19             =cut
20              
21             package RDF::Query::Node::Blank;
22              
23 36     36   164 use strict;
  36         41  
  36         799  
24 36     36   115 use warnings;
  36         36  
  36         704  
25 36     36   108 no warnings 'redefine';
  36         43  
  36         849  
26 36     36   119 use base qw(RDF::Query::Node RDF::Trine::Node::Blank);
  36         40  
  36         4193  
27              
28 36     36   1976131 use Data::Dumper;
  36         52  
  36         1417  
29 36     36   135 use Scalar::Util qw(blessed);
  36         45  
  36         1273  
30 36     36   152 use Carp qw(carp croak confess);
  36         44  
  36         2077  
31              
32             ######################################################################
33              
34             our ($VERSION);
35             BEGIN {
36 36     36   4838 $VERSION = '2.918';
37             }
38              
39             ######################################################################
40              
41             use overload '<=>' => \&_cmp,
42             'cmp' => \&_cmp,
43 2     2   710 '<' => sub { _cmp(@_[0,1]) == -1 },
44 1     1   418 '>' => sub { _cmp(@_[0,1]) == 1 },
45 1     1   398 '!=' => sub { _cmp(@_[0,1]) != 0 },
46 1     1   424 '==' => sub { _cmp(@_[0,1]) == 0 },
47 0     0   0 '+' => sub { $_[0] },
48 105     105   3576 '""' => sub { $_[0]->sse },
49 36     36   178 ;
  36         40  
  36         564  
50              
51             sub _cmp {
52 6     6   8 my $nodea = shift;
53 6         8 my $nodeb = shift;
54 6         23 my $l = Log::Log4perl->get_logger("rdf.query.node.blank");
55 6         578 $l->debug("blank comparison: " . Dumper($nodea, $nodeb));
56 6 50       412 return 1 unless blessed($nodeb);
57 6 50       31 return -1 if ($nodeb->isa('RDF::Trine::Node::Nil'));
58 6 100       34 return -1 if ($nodeb->isa('RDF::Query::Node::Literal'));
59 5 100       19 return -1 if ($nodeb->isa('RDF::Query::Node::Resource'));
60 4 50       9 return 1 unless ($nodeb->isa('RDF::Query::Node::Blank'));
61 4         11 my $cmp = $nodea->blank_identifier cmp $nodeb->blank_identifier;
62 4         25 $l->debug("-> $cmp");
63 4         65 return $cmp;
64             }
65              
66             =item C<< new ( [ $name ] ) >>
67              
68             Returns a new Blank node object. If C<< $name >> is supplied, it will be used as
69             the blank node identifier. Otherwise a time-based identifier will be generated
70             and used.
71              
72             =cut
73              
74             sub new {
75 142     142 1 827 my $class = shift;
76 142         197 my $name = shift;
77 142 100       349 unless (defined($name)) {
78 3         14 $name = 'r' . time() . 'r' . $RDF::Trine::Node::Blank::COUNTER++;
79             }
80 142         589 return $class->_new( $name );
81             }
82              
83             =item C<< as_sparql >>
84              
85             Returns the SPARQL string for this node.
86              
87             =cut
88              
89             sub as_sparql {
90 8     8 1 49 my $self = shift;
91 8         31 return $self->sse;
92             }
93              
94             =item C<< as_hash >>
95              
96             Returns the query as a nested set of plain data structures (no objects).
97              
98             =cut
99              
100             sub as_hash {
101 0     0 1 0 my $self = shift;
102 0         0 my $context = shift;
103             return {
104 0         0 type => 'node',
105             blank => $self->blank_identifier,
106             };
107             }
108              
109             =item C<< make_distinguished_variable >>
110              
111             Returns a new variable based on this blank node.
112              
113             =cut
114              
115             sub make_distinguished_variable {
116 38     38 1 34 my $self = shift;
117 38         77 my $id = $self->blank_identifier;
118 38         120 my $name = '__ndv_' . $id;
119 38         84 my $var = RDF::Query::Node::Variable->new( $name );
120 38         173 return $var;
121             }
122              
123              
124             1;
125              
126             __END__
127              
128             =back
129              
130             =head1 AUTHOR
131              
132             Gregory Todd Williams <gwilliams@cpan.org>
133              
134             =cut