| 1 | # RDF::Trine::Iterator::Graph::Materialized | ||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | RDF::Trine::Iterator::Graph::Materialized - Materialized graph class | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 VERSION | ||||||||||||
| 9 | |||||||||||||
| 10 | This document describes RDF::Trine::Iterator::Graph::Materialized version 1.019 | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||
| 13 | |||||||||||||
| 14 | use RDF::Trine::Iterator; | ||||||||||||
| 15 | |||||||||||||
| 16 | my $iterator = RDF::Trine::Iterator::Graph::Materialized->new( \@data ); | ||||||||||||
| 17 | while (my $statement = $iterator->next) { | ||||||||||||
| 18 | # do something with $statement | ||||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | my $iterator = RDF::Trine::Iterator::Graph->new( \&code ); | ||||||||||||
| 22 | my $miter = $iterator->materialize; | ||||||||||||
| 23 | while (my $statement = $miter->next) { | ||||||||||||
| 24 | # do something with $statement | ||||||||||||
| 25 | } | ||||||||||||
| 26 | $miter->reset; # start the iteration again | ||||||||||||
| 27 | while (my $statement = $miter->next) { | ||||||||||||
| 28 | # ... | ||||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 METHODS | ||||||||||||
| 32 | |||||||||||||
| 33 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||
| 34 | L<RDF::Trine::Iterator::Graph> class. | ||||||||||||
| 35 | |||||||||||||
| 36 | =over 4 | ||||||||||||
| 37 | |||||||||||||
| 38 | =cut | ||||||||||||
| 39 | |||||||||||||
| 40 | package RDF::Trine::Iterator::Graph::Materialized; | ||||||||||||
| 41 | |||||||||||||
| 42 | 68 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | 68 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | 68 | ▶ | no warnings 'redefine'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 68 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 46 | 68 | ▶ | use Scalar::Util qw(reftype); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | 68 | ▶ | use base qw(RDF::Trine::Iterator::Graph); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | |||||||||||||
| 49 | 68 | our ($VERSION); | |||||||||||
| 50 | 68 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 51 | 68 | $VERSION = '1.019'; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | =item C<< new ( \@results, %args ) >> | ||||||||||||
| 55 | |||||||||||||
| 56 | Returns a new materialized graph interator. Results must be a reference to an | ||||||||||||
| 57 | array containing individual results. | ||||||||||||
| 58 | |||||||||||||
| 59 | =cut | ||||||||||||
| 60 | |||||||||||||
| 61 | 3 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||
| 62 | 3 | my $class = shift; | |||||||||||
| 63 | 3 | ▶ | my $data = shift || []; | ||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 64 | 3 | ▶ | Carp::confess unless (scalar(@_) % 2 == 0); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 3 | my %args = @_; | |||||||||||
| 66 | |||||||||||||
| 67 | 3 | ▶ | if (reftype($data) eq 'CODE') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | 1 | my @data; | |||||||||||
| 69 | 1 | ▶ | while (my $d = $data->()) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 3 | push(@data,$d); | |||||||||||
| 71 | } | ||||||||||||
| 72 | 1 | $data = \@data; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 3 | ▶ | Carp::confess unless (reftype($data) eq 'ARRAY'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | |||||||||||||
| 77 | 3 | my $type = 'graph'; | |||||||||||
| 78 | 3 | my $index = 0; | |||||||||||
| 79 | 6 | ▶ | my $stream = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 80 | 6 | my $data = $data->[ $index++ ]; | |||||||||||
| 81 | 6 | ▶ | unless (defined($data)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 1 | $index = 0; | |||||||||||
| 83 | } | ||||||||||||
| 84 | 6 | return $data; | |||||||||||
| 85 | 3 | }; | |||||||||||
| 86 | 3 | my $self = $class->SUPER::new( $stream, %args ); | |||||||||||
| 87 | 3 | $self->{_data} = $data; | |||||||||||
| 88 | 3 | $self->{_index} = \$index; | |||||||||||
| 89 | |||||||||||||
| 90 | 3 | return $self; | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | =item C<< reset >> | ||||||||||||
| 94 | |||||||||||||
| 95 | Returns the iterator to its starting position. | ||||||||||||
| 96 | |||||||||||||
| 97 | =cut | ||||||||||||
| 98 | |||||||||||||
| 99 | 2 | ▶ | sub reset { | ||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 100 | 2 | my $self = shift; | |||||||||||
| 101 | 2 | ${ $self->{_index} } = 0; | |||||||||||
| 102 | } | ||||||||||||
| 103 | |||||||||||||
| 104 | =item C<< next >> | ||||||||||||
| 105 | |||||||||||||
| 106 | Returns the next item in the iterator. | ||||||||||||
| 107 | |||||||||||||
| 108 | =cut | ||||||||||||
| 109 | |||||||||||||
| 110 | 6 | ▶ | sub next { | ||||||||||
|
Subroutine
next: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 111 | 6 | my $self = shift; | |||||||||||
| 112 | 6 | my $data = $self->SUPER::next; | |||||||||||
| 113 | 6 | ▶ | unless (defined($data)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 1 | $self->{_finished} = 0; | |||||||||||
| 115 | } | ||||||||||||
| 116 | 6 | return $data; | |||||||||||
| 117 | } | ||||||||||||
| 118 | |||||||||||||
| 119 | =item C<< length >> | ||||||||||||
| 120 | |||||||||||||
| 121 | Returns the number of elements in the iterator. | ||||||||||||
| 122 | |||||||||||||
| 123 | =cut | ||||||||||||
| 124 | |||||||||||||
| 125 | 3 | ▶ | sub length { | ||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 126 | 3 | my $self = shift; | |||||||||||
| 127 | 3 | return scalar(@{ $self->{ _data } }); | |||||||||||
| 128 | } | ||||||||||||
| 129 | |||||||||||||
| 130 | 68 | 1; | |||||||||||
| 131 | |||||||||||||
| 132 | =back | ||||||||||||
| 133 | |||||||||||||
| 134 | =head1 BUGS | ||||||||||||
| 135 | |||||||||||||
| 136 | Please report any bugs or feature requests to through the GitHub web interface | ||||||||||||
| 137 | at L<https://github.com/kasei/perlrdf/issues>. | ||||||||||||
| 138 | |||||||||||||
| 139 | =head1 AUTHOR | ||||||||||||
| 140 | |||||||||||||
| 141 | Gregory Todd Williams C<< <gwilliams@cpan.org> >> | ||||||||||||
| 142 | |||||||||||||
| 143 | =head1 COPYRIGHT | ||||||||||||
| 144 | |||||||||||||
| 145 | Copyright (c) 2006-2012 Gregory Todd Williams. This | ||||||||||||
| 146 | program is free software; you can redistribute it and/or modify it under | ||||||||||||
| 147 | the same terms as Perl itself. | ||||||||||||
| 148 | |||||||||||||
| 149 | =cut | ||||||||||||