line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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.017 |
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
|
|
|
68
|
|
434
|
use strict; |
|
68
|
|
|
|
|
158
|
|
|
68
|
|
|
|
|
1725
|
|
45
|
68
|
|
|
68
|
|
352
|
use warnings; |
|
68
|
|
|
|
|
147
|
|
|
68
|
|
|
|
|
1617
|
|
46
|
68
|
|
|
68
|
|
381
|
no warnings 'redefine'; |
|
68
|
|
|
|
|
151
|
|
|
68
|
|
|
|
|
1909
|
|
47
|
68
|
|
|
68
|
|
348
|
use Data::Dumper; |
|
68
|
|
|
|
|
161
|
|
|
68
|
|
|
|
|
3038
|
|
48
|
68
|
|
|
68
|
|
414
|
use base qw(RDF::Trine::Iterator::Bindings); |
|
68
|
|
|
|
|
155
|
|
|
68
|
|
|
|
|
5684
|
|
49
|
|
|
|
|
|
|
|
50
|
68
|
|
|
68
|
|
408
|
use Scalar::Util qw(blessed reftype); |
|
68
|
|
|
|
|
156
|
|
|
68
|
|
|
|
|
3970
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
our ($VERSION); |
53
|
|
|
|
|
|
|
BEGIN { |
54
|
68
|
|
|
68
|
|
18935
|
$VERSION = '1.017'; |
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
|
|
|
|
|
|
|
sub new { |
65
|
4
|
|
|
4
|
1
|
42
|
my $class = shift; |
66
|
4
|
|
50
|
|
|
31
|
my $data = shift || []; |
67
|
4
|
|
50
|
|
|
23
|
my $names = shift || []; |
68
|
4
|
50
|
|
|
|
21
|
Carp::confess unless (scalar(@_) % 2 == 0); |
69
|
4
|
|
|
|
|
13
|
my %args = @_; |
70
|
|
|
|
|
|
|
|
71
|
4
|
100
|
|
|
|
30
|
if (reftype($data) eq 'CODE') { |
72
|
1
|
|
|
|
|
4
|
my @rows; |
73
|
1
|
|
|
|
|
4
|
while (my $row = $data->()) { |
74
|
4
|
|
|
|
|
21
|
push(@rows, $row); |
75
|
|
|
|
|
|
|
} |
76
|
1
|
|
|
|
|
6
|
$data = \@rows; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
4
|
50
|
|
|
|
20
|
Carp::confess "not an ARRAY: " . Dumper($data) unless (reftype($data) eq 'ARRAY'); |
80
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
12
|
my $type = 'bindings'; |
82
|
4
|
|
|
|
|
10
|
my $index = 0; |
83
|
|
|
|
|
|
|
my $stream = sub { |
84
|
25
|
|
|
25
|
|
53
|
my $data = $data->[ $index++ ]; |
85
|
25
|
100
|
|
|
|
62
|
unless (defined($data)) { |
86
|
5
|
|
|
|
|
13
|
$index = 0; |
87
|
|
|
|
|
|
|
} |
88
|
25
|
|
|
|
|
54
|
return $data; |
89
|
4
|
|
|
|
|
21
|
}; |
90
|
4
|
|
|
|
|
35
|
my $self = $class->SUPER::new( $stream, $names, %args ); |
91
|
4
|
|
|
|
|
13
|
$self->{_data} = $data; |
92
|
4
|
|
|
|
|
13
|
$self->{_index} = \$index; |
93
|
|
|
|
|
|
|
|
94
|
4
|
|
|
|
|
18
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item C<< reset >> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Returns the iterator to its starting position. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub reset { |
104
|
3
|
|
|
3
|
1
|
464
|
my $self = shift; |
105
|
3
|
|
|
|
|
7
|
${ $self->{_index} } = 0; |
|
3
|
|
|
|
|
11
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item C<< next >> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns the next item in the iterator. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub next { |
115
|
25
|
|
|
25
|
1
|
2765
|
my $self = shift; |
116
|
25
|
|
|
|
|
83
|
my $data = $self->SUPER::next; |
117
|
25
|
100
|
|
|
|
61
|
unless (defined($data)) { |
118
|
5
|
|
|
|
|
14
|
$self->{_finished} = 0; |
119
|
|
|
|
|
|
|
} |
120
|
25
|
|
|
|
|
65
|
return $data; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<< length >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns the number of elements in the iterator. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub length { |
130
|
2
|
|
|
2
|
1
|
886
|
my $self = shift; |
131
|
2
|
|
|
|
|
6
|
return scalar(@{ $self->{ _data } }); |
|
2
|
|
|
|
|
11
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 BUGS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Please report any bugs or feature requests to through the GitHub web interface |
143
|
|
|
|
|
|
|
at L<https://github.com/kasei/perlrdf/issues>. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Gregory Todd Williams C<< <gwilliams@cpan.org> >> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Copyright (c) 2006-2012 Gregory Todd Williams. This |
152
|
|
|
|
|
|
|
program is free software; you can redistribute it and/or modify it under |
153
|
|
|
|
|
|
|
the same terms as Perl itself. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |