| 1 | 50 | ▶ | use v5.14; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 50 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Attean::Result - SPARQL Result | ||
| 7 | |||
| 8 | =head1 VERSION | ||
| 9 | |||
| 10 | This document describes Attean::Result version 0.040 | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | use v5.14; | ||
| 15 | use Attean; | ||
| 16 | my $result = Attean::Result->new(bindings => { name => $literal, homepage => $iri } ); | ||
| 17 | my @vars = $result->variables; # ('name', 'homepage') | ||
| 18 | my $term = $result->value('name'); # $term == $literal | ||
| 19 | |||
| 20 | =head1 DESCRIPTION | ||
| 21 | |||
| 22 | The Attean::Result class represents a SPARQL result (a set of bindings from | ||
| 23 | variable names to L<term|Attean::API::Term>s). | ||
| 24 | It conforms to the L<Attean::API::Result|Attean::API::Binding> role. | ||
| 25 | |||
| 26 | =head1 METHODS | ||
| 27 | |||
| 28 | =over 4 | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | 50 | package Attean::Result 0.040 { | |
| 33 | 50 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 34 | 50 | ▶ | use Types::Standard qw(HashRef ConsumerOf); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 35 | 50 | ▶ | use Attean::API::Binding; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 36 | 50 | ▶ | use namespace::clean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | 50 | with 'Attean::API::Result'; | |
| 39 | |||
| 40 | =item C<< bindings >> | ||
| 41 | |||
| 42 | Returns the HASH reference containing the variable bindings for this result. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | 4 | ▶ | has 'bindings' => (is => 'ro', isa => HashRef[ConsumerOf['Attean::API::TermOrTriple']], default => sub { +{} }); |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 47 | |||
| 48 | # sub BUILD { | ||
| 49 | # my $self = shift; | ||
| 50 | # my $args = shift; | ||
| 51 | # use Data::Dumper; | ||
| 52 | # my $b = $args->{bindings}; | ||
| 53 | # my $keys = [keys %$b]; | ||
| 54 | # if (scalar(@$keys) == 2) { | ||
| 55 | # Carp::cluck 'NEW RESULT CONSTRUCTED with variables ' . Dumper($keys); | ||
| 56 | # } | ||
| 57 | # } | ||
| 58 | |||
| 59 | =item C<< value( $name ) >> | ||
| 60 | |||
| 61 | Returns the term object bound to the C<< $name >>d variable, or undef if the | ||
| 62 | name does not map to a term. | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | 1112 | ▶ | sub value { |
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||
| 67 | 1112 | my $self = shift; | |
| 68 | 1112 | my $k = shift; | |
| 69 | 1112 | return $self->bindings->{$k}; | |
| 70 | } | ||
| 71 | |||
| 72 | =item C<< variables >> | ||
| 73 | |||
| 74 | Returns a list of the variable names that are bound to terms in this result | ||
| 75 | object. | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | 311 | ▶ | sub variables { |
|
Subroutine
variables: called CC=1 SCAR=0.0
Pod
documented
| |||
| 80 | 311 | my $self = shift; | |
| 81 | 311 | return keys %{ $self->bindings }; | |
| 82 | } | ||
| 83 | |||
| 84 | =item C<< as_string >> | ||
| 85 | |||
| 86 | Returns a string serialization of the variable bindings contained in the result. | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | 22 | ▶ | sub as_string { |
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||
| 91 | 22 | my $self = shift; | |
| 92 | 22 | my @vars = $self->variables; | |
| 93 | 22 | my @strs = map { join('=', $_, $self->value($_)->ntriples_string) } sort $self->variables; | |
| 94 | 22 | return '{' . join(', ', @strs) . '}'; | |
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | 50 | 1; | |
| 99 | |||
| 100 | __END__ | ||