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.918.
11              
12             =cut
13              
14             package RDF::Query::Node::Variable;
15              
16 36     36   131 use strict;
  36         48  
  36         848  
17 36     36   116 use warnings;
  36         40  
  36         749  
18 36     36   109 no warnings 'redefine';
  36         41  
  36         991  
19 36     36   130 use base qw(RDF::Query::Node RDF::Trine::Node::Variable);
  36         45  
  36         3008  
20              
21 36     36   147 use Data::Dumper;
  36         45  
  36         1345  
22 36     36   131 use Scalar::Util qw(blessed);
  36         49  
  36         1284  
23 36     36   129 use Carp qw(carp croak confess);
  36         40  
  36         1974  
24              
25             ######################################################################
26              
27             our ($VERSION);
28             BEGIN {
29 36     36   1327 $VERSION = '2.918';
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   138 use overload '""' => sub { $_[0]->sse };
  36     287   45  
  36         239  
  287         2997  
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 1035     1035 1 1795 my $class = shift;
56 1035         1509 my $name = shift;
57 1035 100       1909 unless (defined($name)) {
58 45         92 $name = 'v' . time() . 'r' . $COUNTER++;
59             }
60 1035         3663 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 395     395 1 1717 my $self = shift;
71 395         980 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   5596 use strict;
  36         102  
  36         586  
92 36     36   107 use warnings;
  36         46  
  36         741  
93 36     36   127 use base qw(RDF::Query::Node::Variable);
  36         52  
  36         2062  
94 36     36   144 use Scalar::Util qw(blessed refaddr);
  36         47  
  36         8494  
95              
96             =begin private
97              
98             =item C<< new >>
99              
100             =cut
101              
102             {my %vars;
103             sub new {
104 21     21   43 my $class = shift;
105 21         36 my $name = shift;
106 21         32 my @vars = @_;
107 21         57 my $self = $class->SUPER::new( $name );
108 21 50       130 if (@vars) {
109 21 50       34 $vars{ refaddr($self) } = [map {blessed($_) ? $_ : RDF::Query::Node::Variable->new($_)} @vars];
  21         156  
110             }
111 21         67 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         9 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   43 my $self = shift;
139 21         293 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