File Coverage

blib/lib/RDF/Query/Node/Variable.pm
Criterion Covered Total %
statement 57 66 86.3
branch 4 10 40.0
condition n/a
subroutine 19 22 86.3
pod 3 3 100.0
total 83 101 82.1


line stmt bran cond sub pod time code
1             # RDF::Query::Node::Variable
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Node::Variable - RDF Node class for variables
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Node::Variable version 2.916.
11              
12             =cut
13              
14             package RDF::Query::Node::Variable;
15              
16 36     36   179 use strict;
  36         71  
  36         861  
17 36     36   177 use warnings;
  36         69  
  36         874  
18 36     36   170 no warnings 'redefine';
  36         75  
  36         1152  
19 36     36   175 use base qw(RDF::Query::Node RDF::Trine::Node::Variable);
  36         70  
  36         4046  
20              
21 36     36   197 use Data::Dumper;
  36         69  
  36         1815  
22 36     36   245 use Scalar::Util qw(blessed);
  36         80  
  36         1731  
23 36     36   249 use Carp qw(carp croak confess);
  36         79  
  36         2905  
24              
25             ######################################################################
26              
27             our ($VERSION);
28             BEGIN {
29 36     36   1830 $VERSION = '2.916';
30             }
31              
32             ######################################################################
33              
34             =head1 METHODS
35              
36             =head1 METHODS
37              
38             Beyond the methods documented below, this class inherits methods from the
39             L<RDF::Query::Node> and L<RDF::Trine::Node::Variable> classes.
40              
41             =over 4
42              
43             =cut
44              
45 36     36   199 use overload '""' => sub { $_[0]->sse };
  36     287   79  
  36         417  
  287         4894  
46              
47             =item C<< new ( $name ) >>
48              
49             Returns a new variable object.
50              
51             =cut
52              
53             my $COUNTER = 0;
54             sub new {
55 1021     1021 1 2674 my $class = shift;
56 1021         2102 my $name = shift;
57 1021 100       2469 unless (defined($name)) {
58 45         132 $name = 'v' . time() . 'r' . $COUNTER++;
59             }
60 1021         4086 return $class->SUPER::new( $name );
61             }
62              
63             =item C<< as_sparql >>
64              
65             Returns the SPARQL string for this node.
66              
67             =cut
68              
69             sub as_sparql {
70 381     381 1 2389 my $self = shift;
71 381         1158 return $self->sse;
72             }
73              
74             =item C<< as_hash >>
75              
76             Returns the query as a nested set of plain data structures (no objects).
77              
78             =cut
79              
80             sub as_hash {
81 0     0 1 0 my $self = shift;
82 0         0 my $context = shift;
83             return {
84 0         0 type => 'node',
85             variable => $self->name,
86             };
87             }
88              
89             package RDF::Query::Node::Variable::ExpressionProxy;
90              
91 36     36   7524 use strict;
  36         77  
  36         846  
92 36     36   173 use warnings;
  36         74  
  36         1069  
93 36     36   197 use base qw(RDF::Query::Node::Variable);
  36         89  
  36         3277  
94 36     36   278 use Scalar::Util qw(blessed refaddr);
  36         85  
  36         12039  
95              
96             =begin private
97              
98             =item C<< new >>
99              
100             =cut
101              
102             {my %vars;
103             sub new {
104 21     21   45 my $class = shift;
105 21         30 my $name = shift;
106 21         43 my @vars = @_;
107 21         70 my $self = $class->SUPER::new( $name );
108 21 50       162 if (@vars) {
109 21 50       50 $vars{ refaddr($self) } = [map {blessed($_) ? $_ : RDF::Query::Node::Variable->new($_)} @vars];
  21         171  
110             }
111 21         93 return $self;
112             }
113              
114             =item C<< as_sparql >>
115              
116             =cut
117              
118             sub as_sparql {
119 2     2   3 my $self = shift;
120 2         12 return $self->name;
121             }
122              
123             =item C<< referenced_variables >>
124              
125             =cut
126              
127             sub referenced_variables {
128 0     0   0 my $self = shift;
129 0 0       0 my @vars = map { blessed($_) ? $_->name : $_ } @{ $vars{ refaddr($self) } || [] };
  0 0       0  
  0         0  
130 0         0 return RDF::Query::_uniq(@vars);
131             }
132              
133             sub nonaggregated_referenced_variables {
134 0     0   0 return;
135             }
136              
137             sub DESTROY {
138 21     21   41 my $self = shift;
139 21         302 delete $vars{ refaddr($self) };
140             }
141             }
142              
143             =end private
144              
145             =cut
146              
147             1;
148              
149             __END__
150              
151             =back
152              
153             =head1 AUTHOR
154              
155             Gregory Todd Williams <gwilliams@cpan.org>
156              
157             =cut