| 1 | # RDF::Trine::Iterator::Bindings::Materialized | ||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | RDF::Trine::Iterator::Bindings::Materialized - Materialized bindings class | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 VERSION | ||||||||||||
| 9 | |||||||||||||
| 10 | This document describes RDF::Trine::Iterator::Bindings::Materialized version 1.019 | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||
| 13 | |||||||||||||
| 14 | use RDF::Trine::Iterator; | ||||||||||||
| 15 | |||||||||||||
| 16 | my $iterator = RDF::Trine::Iterator::Bindings::Materialized->new( \@data, \@names ); | ||||||||||||
| 17 | while (my $row = $iterator->next) { | ||||||||||||
| 18 | my @vars = keys %$row; | ||||||||||||
| 19 | # do something with @vars | ||||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | my $iterator = RDF::Trine::Iterator::Bindings->new( \&code, \@names ); | ||||||||||||
| 23 | my $miter = $iterator->materialize; | ||||||||||||
| 24 | while (my $row = $miter->next) { | ||||||||||||
| 25 | my @vars = keys %$row; | ||||||||||||
| 26 | # do something with @vars | ||||||||||||
| 27 | } | ||||||||||||
| 28 | $miter->reset; # start the iteration again | ||||||||||||
| 29 | while (my $row = $miter->next) { | ||||||||||||
| 30 | # ... | ||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | =head1 METHODS | ||||||||||||
| 34 | |||||||||||||
| 35 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||
| 36 | L<RDF::Trine::Iterator::Bindings> class. | ||||||||||||
| 37 | |||||||||||||
| 38 | =over 4 | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | package RDF::Trine::Iterator::Bindings::Materialized; | ||||||||||||
| 43 | |||||||||||||
| 44 | 68 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 68 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 46 | 68 | ▶ | no warnings 'redefine'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | 68 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 68 | ▶ | use base qw(RDF::Trine::Iterator::Bindings); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | |||||||||||||
| 50 | 68 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 51 | |||||||||||||
| 52 | 68 | our ($VERSION); | |||||||||||
| 53 | 68 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | 68 | $VERSION = '1.019'; | |||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | =item C<< new ( \@results, \@names, %args ) >> | ||||||||||||
| 58 | |||||||||||||
| 59 | Returns a new materialized bindings interator. Results must be a reference to an | ||||||||||||
| 60 | array containing individual results. | ||||||||||||
| 61 | |||||||||||||
| 62 | =cut | ||||||||||||
| 63 | |||||||||||||
| 64 | 4 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||
| 65 | 4 | my $class = shift; | |||||||||||
| 66 | 4 | ▶ | my $data = shift || []; | ||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 67 | 4 | ▶ | my $names = shift || []; | ||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 68 | 4 | ▶ | Carp::confess unless (scalar(@_) % 2 == 0); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 69 | 4 | my %args = @_; | |||||||||||
| 70 | |||||||||||||
| 71 | 4 | ▶ | if (reftype($data) eq 'CODE') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | 1 | my @rows; | |||||||||||
| 73 | 1 | ▶ | while (my $row = $data->()) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 4 | push(@rows, $row); | |||||||||||
| 75 | } | ||||||||||||
| 76 | 1 | $data = \@rows; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | 4 | ▶ | Carp::confess "not an ARRAY: " . Dumper($data) unless (reftype($data) eq 'ARRAY'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | 4 | my $type = 'bindings'; | |||||||||||
| 82 | 4 | my $index = 0; | |||||||||||
| 83 | 25 | ▶ | my $stream = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 84 | 25 | my $data = $data->[ $index++ ]; | |||||||||||
| 85 | 25 | ▶ | unless (defined($data)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | 5 | $index = 0; | |||||||||||
| 87 | } | ||||||||||||
| 88 | 25 | return $data; | |||||||||||
| 89 | 4 | }; | |||||||||||
| 90 | 4 | my $self = $class->SUPER::new( $stream, $names, %args ); | |||||||||||
| 91 | 4 | $self->{_data} = $data; | |||||||||||
| 92 | 4 | $self->{_index} = \$index; | |||||||||||
| 93 | |||||||||||||
| 94 | 4 | return $self; | |||||||||||
| 95 | } | ||||||||||||
| 96 | |||||||||||||
| 97 | =item C<< reset >> | ||||||||||||
| 98 | |||||||||||||
| 99 | Returns the iterator to its starting position. | ||||||||||||
| 100 | |||||||||||||
| 101 | =cut | ||||||||||||
| 102 | |||||||||||||
| 103 | 3 | ▶ | sub reset { | ||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 104 | 3 | my $self = shift; | |||||||||||
| 105 | 3 | ${ $self->{_index} } = 0; | |||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | =item C<< next >> | ||||||||||||
| 109 | |||||||||||||
| 110 | Returns the next item in the iterator. | ||||||||||||
| 111 | |||||||||||||
| 112 | =cut | ||||||||||||
| 113 | |||||||||||||
| 114 | 25 | ▶ | sub next { | ||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 115 | 25 | my $self = shift; | |||||||||||
| 116 | 25 | my $data = $self->SUPER::next; | |||||||||||
| 117 | 25 | ▶ | unless (defined($data)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 5 | $self->{_finished} = 0; | |||||||||||
| 119 | } | ||||||||||||
| 120 | 25 | return $data; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | =item C<< length >> | ||||||||||||
| 124 | |||||||||||||
| 125 | Returns the number of elements in the iterator. | ||||||||||||
| 126 | |||||||||||||
| 127 | =cut | ||||||||||||
| 128 | |||||||||||||
| 129 | 2 | ▶ | sub length { | ||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 130 | 2 | my $self = shift; | |||||||||||
| 131 | 2 | return scalar(@{ $self->{ _data } }); | |||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | 68 | 1; | |||||||||||
| 135 | |||||||||||||
| 136 | __END__ | ||||||||||||