File Coverage

blib/lib/RDF/Query/Expression/Alias.pm
Criterion Covered Total %
statement 38 48 79.1
branch n/a
condition n/a
subroutine 13 15 86.6
pod 7 7 100.0
total 58 70 82.8


line stmt bran cond sub pod time code
1             # RDF::Query::Expression::Alias
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Expression::Alias - Class for aliasing expressions with variable names
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Expression::Alias version 2.915_01.
11              
12             =cut
13              
14             package RDF::Query::Expression::Alias;
15              
16 36     36   178 use strict;
  36         68  
  36         854  
17 36     36   236 use warnings;
  36         62  
  36         867  
18 36     36   174 no warnings 'redefine';
  36         56  
  36         1219  
19 36     36   180 use base qw(RDF::Query::Expression);
  36         158  
  36         2762  
20              
21 36     36   199 use Data::Dumper;
  36         532  
  36         1633  
22 36     36   174 use Scalar::Util qw(blessed);
  36         86  
  36         1730  
23 36     36   203 use Carp qw(carp croak confess);
  36         63  
  36         2965  
24              
25             ######################################################################
26              
27             our ($VERSION);
28             BEGIN {
29 36     36   12396 $VERSION = '2.915_01';
30             }
31              
32             ######################################################################
33              
34             =head1 METHODS
35              
36             Beyond the methods documented below, this class inherits methods from the
37             L<RDF::Query::Expression> class.
38              
39             =over 4
40              
41             =cut
42              
43             =item C<< name >>
44              
45             Returns the variable name of the aliased expression.
46              
47             =cut
48              
49             sub name {
50 254     254 1 361 my $self = shift;
51 254         585 return $self->alias->name;
52             }
53              
54             =item C<< alias >>
55              
56             Returns the variable object of the aliased expression.
57              
58             =cut
59              
60             sub alias {
61 284     284 1 352 my $self = shift;
62 284         872 my ($alias) = $self->operands;
63 284         1037 return $alias;
64             }
65              
66             =item C<< expression >>
67              
68             Returns the expression object of the aliased expression.
69              
70             =cut
71              
72             sub expression {
73 148     148 1 505 my $self = shift;
74 148         404 return ($self->operands)[1];
75             }
76              
77             =item C<< sse >>
78              
79             Returns the SSE string for this algebra expression.
80              
81             =cut
82              
83             sub sse {
84 92     92 1 129 my $self = shift;
85 92         109 my $context = shift;
86            
87 92         227 return sprintf(
88             '(alias ?%s %s)',
89             $self->name,
90             $self->expression->sse( $context ),
91             );
92             }
93              
94             =item C<< as_sparql >>
95              
96             Returns the SPARQL string for this algebra expression.
97              
98             =cut
99              
100             sub as_sparql {
101 1     1 1 3 my $self = shift;
102 1         2 my $context = shift;
103 1         2 my $indent = shift;
104 1         3 my $alias = $self->alias;
105 1         4 my $expr = $self->expression;
106 1         5 return sprintf("(%s AS %s)", $expr->as_sparql, $alias->as_sparql);
107             }
108              
109             =item C<< evaluate ( $query, \%bound, $context ) >>
110              
111             Evaluates the expression using the supplied bound variables.
112             Will return a RDF::Query::Node object.
113              
114             =cut
115              
116             sub evaluate {
117 0     0 1   my $self = shift;
118 0           my $query = shift;
119 0           my $bound = shift;
120 0           my $ctx = shift;
121 0           my $expr = $self->expression;
122 0           my $value = $query->var_or_expr_value( $bound, $expr, $ctx );
123 0           return $value;
124             }
125              
126             =item C<< as_hash >>
127              
128             Returns the alias as a nested set of plain data structures (no objects).
129              
130             =cut
131              
132             sub as_hash {
133 0     0 1   my $self = shift;
134 0           my $context = shift;
135             return {
136 0           type => 'alias',
137             alias => $self->alias->as_hash,
138             expression => $self->expression->as_hash,
139             };
140             }
141              
142              
143             1;
144              
145             __END__
146              
147             =back
148              
149             =head1 AUTHOR
150              
151             Gregory Todd Williams <gwilliams@cpan.org>
152              
153             =cut