DBIx-Class-SingletonRows

 view release on metacpan or  search on metacpan

lib/DBIx/Class/SingletonRows.pm  view on Meta::CPAN

into singletons

=head1 DESCRIPTION

When you do this with DBIx::Class:

    my $row = $schema->...

    my $row2 = update_and_return();

    sub update_and_return {
        my $row = $schema->...
        $row->somefield("HLAGH");
        $row->update();
        return $row;
    }

then even if both C<$row> and C<$row2> have the same row_id, they'll have
different values for C<somefield>.  This irritates me, so this mixin fixes it.

=head1 SYNOPSIS

t/02-singletonness.t  view on Meta::CPAN

    ok(1 == $outer_row->_DCS_refcount(), "'inner' var went out of scope, refcount == 1 in cache");
    ok($outer_row->somedata() eq 'four', "'outer' row still magickally updated");
}

is_deeply(
    $DBIx::Class::SingletonRows::cache->{'DBIx::Class::SingletonRows::Tests::TestSchema::Hlagh'},
    {},
    "'outer' var now out of scope, object expired from cache"
);

sub update_and_return {
    my $row = ($schema->resultset('Hlagh')->search({key1 => 1, key2 => 2}))[0];
    $row->somedata('four');
    $row->update();
    return $row;
}

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 2.757 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )