This file is indexed.

/usr/share/perl5/Alzabo/Runtime/JoinCursor.pm is in libalzabo-perl 0.92-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package Alzabo::Runtime::JoinCursor;

use strict;
use vars qw($VERSION);

use Alzabo::Exceptions;
use Alzabo::Runtime;

use Params::Validate qw( :all );
Params::Validate::validation_options( on_fail => sub { Alzabo::Exception::Params->throw( error => join '', @_ ) } );

use base qw( Alzabo::Runtime::Cursor );

$VERSION = 2.0;

use constant NEW_SPEC => { statement => { isa => 'Alzabo::DriverStatement' },
                           tables => { type => ARRAYREF },
                         };

sub new
{
    my $proto = shift;
    my $class = ref $proto || $proto;

    my %p = validate( @_, NEW_SPEC );

    my $self = bless { %p,
                       count => 0,
                     }, $class;

    return $self;
}

sub next
{
    my $self = shift;

    my @rows;

    my @data = $self->{statement}->next;

    return unless @data;

    my $i = 0;
    foreach my $t ( @{ $self->{tables} } )
    {

        my %pk;
        my $def = 0;
        foreach my $c ( $t->primary_key )
        {
            $pk{ $c->name } = $data[$i];

            $def = 1 if defined $data[$i];

            $i++;
        }

        unless ($def)
        {
            push @rows, undef;

            my @pre;
            if ( @pre = $t->prefetch )
            {
                $i += @pre;
            }

            next;
        }

        my %prefetch;
        {
            my @pre;
            if ( @pre = $t->prefetch )
            {
                @prefetch{@pre} = @data[ $i .. ($i + $#pre) ];
                $i += @pre;
            }
        }

        my $row = $t->row_by_pk( pk => \%pk,
                                 prefetch => \%prefetch,
                                 @_,
                               );

        push @rows, $row;
    }

    $self->{count}++;

    return @rows;
}

sub all_rows
{
    my $self = shift;

    my @all;
    while ( my @rows = $self->next )
    {
        push @all, [@rows];
    }

    $self->{count} = scalar @all;

    return @all;
}

1;

__END__

=head1 NAME

Alzabo::Runtime::JoinCursor - Cursor that returns arrays of C<Alzabo::Runtime::Row> objects

=head1 SYNOPSIS

  use Alzabo::Runtime::JoinCursor;

  my $cursor = $schema->join( tables => [ $foo, $bar ],
                              where => [ $foo->column('foo_id'), '=', 1 ] );

  while ( my @rows = $cursor->next )
  {
      print $rows[0]->select('foo'), "\n";
      print $rows[1]->select('bar'), "\n";
  }

=head1 DESCRIPTION

Objects in this class are used to return arrays of
Alzabo::Runtime::Row objects when requested.  The cursor does not
preload objects but rather creates them on demand, which is much more
efficient.  For more details on the rational please see L<the
RATIONALE FOR CURSORS section in
Alzabo::Design|Alzabo::Design/RATIONALE FOR CURSORS>.

=head1 INHERITS FROM

L<C<Alzabo::Runtime::Cursor>|Alzabo::Runtime::Cursor>

=head1 METHODS

=head2 next

Returns the next array of
L<C<Alzabo::Runtime::Row>|Alzabo::Runtime::Row> objects or an empty
list if no more are available.

If an individual row could not be fetched, then the array may contain
some C<undef> values.  For outer joins, this is normal behavior, but
for regular joins, this probably indicates a data error.

=head2 all_rows

This method fetches all the rows available from the current point
onwards.  This means that if there are five set of rows that will be
returned when the object is created and you call C<next()> twice,
calling C<all_rows()> after it will only return three sets.

The return value is an array of array references.  Each of these
references represents a single set of rows as they would be returned
from the C<next> method.

=head2 reset

Resets the cursor so that the next L<C<next()>|next> call will return
the first row of the set.

=head2 count

Returns the number of rowsets returned by the cursor so far.

=head2 next_as_hash

Returns the next rows in a hash, where the hash keys are the table
names and the hash values are the row object.  If a table has been
included in the join via an outer join, then it is only included in
the hash if there is a row for that table.

=head1 AUTHOR

Dave Rolsky, <autarch@urth.org>

=cut