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