---
name: "RDF::Trine::Iterator"
section: "3pm"
platform: "linux"
package: "librdf-trine-perl"
version: "1.019-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/RDF::Trine::Iterator"
---

# RDF::Trine::Iterator(3pm)

Iterator class for SPARQL query results

## NAME

RDF::Trine::Iterator - Iterator class for SPARQL query results

## VERSION

This document describes RDF::Trine::Iterator version 1.019.

## SYNOPSIS

```
    use RDF::Trine::Iterator;
    my $iterator = RDF::Trine::Iterator->new( \&data, 'bindings', \@names );
    while (my $row = $iterator->next) {
        my @vars        = keys %$row;
        # do something with @vars
    }
```

## METHODS

- "new ( \\@results, $type, \\@names, %args )"

  - "new ( \\&results, $type, \\@names, %args )"

  Returns a new SPARQL Result interator object. Results must be either an reference to an array containing results or a CODE reference that acts as an iterator, returning successive items when called, and returning undef when the iterator is exhausted.

  `$type` should be one of: bindings, boolean, graph.

- "type"

  Returns the underlying result type (boolean, graph, bindings).

- "is\_boolean"

  Returns true if the underlying result is a boolean value.

- "is\_bindings"

  Returns true if the underlying result is a set of variable bindings.

- "is\_graph"

  Returns true if the underlying result is an RDF graph.

- "to\_string ( $format )"

  Returns a string representation of the stream data in the specified `$format`. If `$format` is missing, defaults to XML serialization. Other options are:

  ```
    http://www.w3.org/2001/sw/DataAccess/json-sparql/
  ```

- "from\_string ( $xml )"

  Returns a new iterator using the supplied XML string in the SPARQL XML Results format.

- "from\_bytes ( $xml )"

  Returns a new iterator using the supplied XML byte sequence (note: not character data) in the SPARQL XML Results format.

- "from\_json ( $json )"

  - "next\_result"

  - "next"

  Returns the next item in the stream.

- "peek"

  Returns the next value from the iterator without consuming it. The value will remain in queue until the next call to `"next"`.

- "current"

  Returns the current item in the stream.

- "end"

  - "finished"

  Returns true if the end of the stream has been reached, false otherwise.

- "open"

  Returns true if the first element of the stream has been retrieved, false otherwise.

- "close"

  Closes the stream. Future attempts to retrieve data from the stream will act as if the stream had been exhausted.

- "concat ( $stream )"

  Returns a new stream resulting from the concatenation of the referant and the argument streams. The new stream uses the stream type, and optional binding names and `"<%args"`\> from the referant stream.

- "seen\_count"

  Returns the count of elements that have been returned by this iterator at the point of invocation.

- "get\_boolean"

  Returns the boolean value of the first item in the stream.

- "get\_all"

  Returns an array containing all the items in the stream.

- "construct\_args"

  Returns the arguments necessary to pass to a stream constructor to re-create this stream (assuming the same closure as the first argument).

- "each ( \\&callback )"

  Calls the callback function once for each item in the iterator, passing the item as an argument to the function. Any arguments to `"each"` beyond the callback function will be passed as supplemental arguments to the callback function.

## FUNCTIONS

- "sgrep { COND } $stream"

  - "smap { EXPR } $stream"

  - "swatch { EXPR } $stream"

  ## DEPENDENCIES

JSON

Scalar::Util

XML::SAX

## BUGS

Please report any bugs or feature requests to through the GitHub web interface at \<https://github.com/kasei/perlrdf/issues\>.

## AUTHOR

Gregory Todd Williams  `"<gwilliams@cpan.org>"`

## COPYRIGHT

Copyright (c) 2006-2012 Gregory Todd Williams. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
