This file is indexed.

/usr/share/perl5/Alzabo/Runtime/RowState/Live.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package Alzabo::Runtime::RowState::Live;

use strict;

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

sub _where
{
    my $class = shift;
    my $row = shift;
    my $sql = shift;

    my ($pk1, @pk) = $row->table->primary_key;

    $sql->where( $pk1, '=', $row->{pk}{ $pk1->name } );
    $sql->and( $_, '=', $row->{pk}{ $_->name } ) foreach @pk;
}

sub _init
{
    my $class = shift;
    my $row = shift;
    my %p = @_;

    $row->{pk} = $row->_make_id_hash(%p);

    while ( my ($k, $v) = each %{ $row->{pk} } )
    {
        $row->{data}{$k} = $v;
    }

    if ( $p{prefetch} )
    {
        while ( my ($k, $v) = each %{ $p{prefetch} } )
        {
            $row->{data}{$k} = $v;
        }
    }
    else
    {
        eval { $class->_get_prefetch_data($row) };

        if ( my $e = $@ )
        {
            return if isa_alzabo_exception( $e, 'Alzabo::Exception::NoSuchRow' );

            rethrow_exception $e;
        }
    }

    unless ( keys %{ $row->{data} } > keys %{ $row->{pk} } )
    {
        # Need to try to fetch something to confirm that this row exists!
        my $sql = ( $row->schema->sqlmaker->
                    select( ($row->table->primary_key)[0] )->
                    from( $row->table ) );

        $class->_where($row, $sql);

        $sql->debug(\*STDERR) if Alzabo::Debug::SQL;
        print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE;

        return
            unless defined $row->schema->driver->one_row( sql => $sql->sql,
                                                          bind => $sql->bind );
    }

    return 1;
}

sub _get_prefetch_data
{
    my $class = shift;
    my $row = shift;

    my @pre = $row->table->prefetch;

    return unless @pre;

    $class->_get_data( $row, @pre );
}

sub _get_data
{
    my $class = shift;
    my $row = shift;

    my %data;
    my @select;
    foreach my $col (@_)
    {
        if ( exists $row->{data}{$col} )
        {
            $data{$col} = $row->{data}{$col};
        }
        else
        {
            push @select, $col;
        }
    }

    return %data unless @select;

    my $sql = ( $row->schema->sqlmaker->
                select( $row->table->columns(@select) )->
                from( $row->table ) );
    $class->_where($row, $sql);

    $sql->debug(\*STDERR) if Alzabo::Debug::SQL;
    print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE;

    my %d;
    @d{@select} =
        $row->schema->driver->one_row( sql  => $sql->sql,
                                       bind => $sql->bind )
            or $row->_no_such_row_error;

    while ( my( $k, $v ) = each %d )
    {
        $row->{data}{$k} = $data{$k} = $v;
    }

    return %data;
}

sub id_as_string
{
    my $class = shift;
    my $row = shift;
    my %p = @_;

    return $row->{id_string} if exists $row->{id_string};

    $row->{id_string} = $row->id_as_string_ext( pk    => $row->{pk},
                                                table => $row->table );
    return $row->{id_string};
}

sub select
{
    my $class = shift;
    my $row = shift;

    my @cols = @_ ? @_ : map { $_->name } $row->table->columns;
    my %data = $class->_get_data( $row, @cols );

    return wantarray ? @data{@cols} : $data{ $cols[0] };
}

sub select_hash
{
    my $class = shift;
    my $row = shift;

    my @cols = @_ ? @_ : map { $_->name } $row->table->columns;

    return $class->_get_data( $row, @cols );
}

sub update
{
    my $class = shift;
    my $row = shift;
    my %data = @_;

    my $schema = $row->schema;

    my @fk; # this never gets populated unless referential integrity
            # checking is on
    my @set;

    my $includes_pk = 0;
    foreach my $k ( sort keys %data )
    {
        # This will throw an exception if the column doesn't exist.
        my $c = $row->table->column($k);

        if ( $row->_cached_data_is_same( $k, $data{$k} ) )
        {
            delete $data{$k};
            next;
        }

        $includes_pk = 1 if $c->is_primary_key;

        Alzabo::Exception::NotNullable->throw
            ( error => $c->name . " column in " . $row->table->name . " table cannot be null.",
              column_name => $c->name,
              table_name  => $c->table->name,
              schema_name => $schema->name,
            )
                unless defined $data{$k} || $c->nullable || defined $c->default;

        push @fk, $row->table->foreign_keys_by_column($c)
            if $schema->referential_integrity;

        push @set, $c => $data{$k};
    }

    return 0 unless keys %data;

    my $sql = ( $schema->sqlmaker->update( $row->table ) );

    $sql->set(@set);

    $class->_where( $row, $sql );

    # If we have foreign keys we'd like all the fiddling to be atomic.
    $schema->begin_work if @fk;

    eval
    {
        foreach my $fk (@fk)
        {
            $fk->register_update( map { $_->name => $data{ $_->name } } $fk->columns_from );
        }

        $sql->debug(\*STDERR) if Alzabo::Debug::SQL;
        print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE;

        $schema->driver->do( sql  => $sql->sql,
                             bind => $sql->bind );

        $schema->commit if @fk;
    };

    if (my $e = $@)
    {
        eval { $schema->rollback };

        rethrow_exception $e;
    }

    while ( my( $k, $v ) = each %data )
    {
        # These can't be stored until they're fetched from the database again
        if ( Alzabo::Utils::safe_isa( $v, 'Alzabo::SQLMaker::Function' ) )
        {
            delete $row->{data}{$k};
            next;
        }

        $row->{data}{$k} = $v;
    }

    $row->_update_pk_hash if $includes_pk;

    return 1;
}

sub refresh
{
    my $class = shift;
    my $row = shift;

    delete $row->{data};

    $class->_get_prefetch_data($row);
}

sub delete
{
    my $class = shift;
    my $row = shift;

    my $schema = $row->schema;

    my @fk;
    if ($schema->referential_integrity)
    {
        @fk = $row->table->all_foreign_keys;
    }

    my $sql = ( $schema->sqlmaker->
                delete->from( $row->table ) );

    $class->_where($row, $sql);

    $schema->begin_work if @fk;
    eval
    {
        foreach my $fk (@fk)
        {
            $fk->register_delete($row);
        }

        $sql->debug(\*STDERR) if Alzabo::Debug::SQL;
        print STDERR Devel::StackTrace->new if Alzabo::Debug::TRACE;

        $schema->driver->do( sql => $sql->sql,
                             bind => $sql->bind );

        $schema->commit if @fk;
    };

    if (my $e = $@)
    {
        eval { $schema->rollback };

        rethrow_exception $e;
    }

    $row->set_state( 'Alzabo::Runtime::RowState::Deleted' );
}

sub is_potential { 0 }

sub is_live { 1 }

sub is_deleted { 0 }


1;

__END__

=head1 NAME

Alzabo::Runtime::RowState::Live - Row objects representing rows in the database

=head1 SYNOPSIS

  my $row = $table->row_by_pk( pk => 1 );

=head1 DESCRIPTION

This state is used for live rows, rows which represent actual rows in
the database.

=head1 METHODS

See L<C<Alzabo::Runtime::Row>|Alzabo::Runtime::Row>.

=head1 AUTHOR

Dave Rolsky, <autarch@urth.org>

=cut