| 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.919. | ||
| 11 | |||
| 12 | =cut | ||
| 13 | |||
| 14 | package RDF::Query::Expression::Alias; | ||
| 15 | |||
| 16 | 36 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 36 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | 36 | ▶ | no warnings 'redefine'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 36 | ▶ | use base qw(RDF::Query::Expression); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | |||
| 21 | 36 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 36 | ▶ | use Scalar::Util qw(blessed); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | 36 | ▶ | use Carp qw(carp croak confess); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | ###################################################################### | ||
| 26 | |||
| 27 | 36 | our ($VERSION); | |
| 28 | 36 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 36 | $VERSION = '2.919'; | |
| 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 | 254 | ▶ | sub name { |
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||
| 50 | 254 | my $self = shift; | |
| 51 | 254 | 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 | 284 | ▶ | sub alias { |
|
Subroutine
alias: called CC=1 SCAR=0.0
Pod
documented
| |||
| 61 | 284 | my $self = shift; | |
| 62 | 284 | my ($alias) = $self->operands; | |
| 63 | 284 | return $alias; | |
| 64 | } | ||
| 65 | |||
| 66 | =item C<< expression >> | ||
| 67 | |||
| 68 | Returns the expression object of the aliased expression. | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | 148 | ▶ | sub expression { |
|
Subroutine
expression: called CC=1 SCAR=0.0
Pod
documented
| |||
| 73 | 148 | my $self = shift; | |
| 74 | 148 | 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 | 92 | ▶ | sub sse { |
|
Subroutine
sse: called CC=1 SCAR=0.0
Pod
documented
| |||
| 84 | 92 | my $self = shift; | |
| 85 | 92 | my $context = shift; | |
| 86 | |||
| 87 | 92 | 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 | 1 | ▶ | sub as_sparql { |
|
Subroutine
as_sparql: called CC=1 SCAR=0.0
Pod
documented
| |||
| 101 | 1 | my $self = shift; | |
| 102 | 1 | my $context = shift; | |
| 103 | 1 | my $indent = shift; | |
| 104 | 1 | my $alias = $self->alias; | |
| 105 | 1 | my $expr = $self->expression; | |
| 106 | 1 | 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 | 0 | ▶ | sub evaluate { |
|
Subroutine
evaluate: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 117 | 0 | 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 | 0 | ▶ | sub as_hash { |
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 133 | 0 | 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 | 36 | 1; | |
| 144 | |||
| 145 | __END__ | ||