File: InCache.pm

package info (click to toggle)
libalzabo-perl 0.87-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,124 kB
  • ctags: 771
  • sloc: perl: 14,590; makefile: 46
file content (93 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download | duplicates (2)
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
package Alzabo::Runtime::RowState::InCache;

use strict;

use base qw(Alzabo::Runtime::RowState::Live);

BEGIN
{
    no strict 'refs';
    foreach my $meth ( qw( select select_hash delete ) )
    {
        my $super = "SUPER::$meth";
        *{__PACKAGE__ . "::$meth"} =
            sub { my $s = shift;

                  $s->refresh(@_) unless $s->_in_cache(@_);

                  $s->$super(@_);
              };
    }
}

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

    my $old_id = $row->id_as_string;

    $class->refresh($row) unless $class->_in_cache($row);

    my $changed = $class->SUPER::update( $row, @_ );

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

    Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );

    Alzabo::Runtime::UniqueRowCache->write_to_cache($row);

    return $changed;
}

sub refresh
{
    my $class = shift;

    $class->SUPER::refresh(@_);

#    return if $class->_in_cache($row); #????
}

sub _in_cache
{
    return
        Alzabo::Runtime::UniqueRowCache->row_in_cache
            ( $_[1]->table->name, $_[1]->id_as_string );
}

sub _write_to_cache
{
    Alzabo::Runtime::UniqueRowCache->write_to_cache( $_[1] );
}


1;

__END__

=head1 NAME

Alzabo::Runtime::RowState::InCache - Cached row objects that represent actual database rows

=head1 SYNOPSIS

  use Alzabo::Runtime::UniqueRowCache;

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

=head1 DESCRIPTION

This state is used for live rows that are cached via the
C<Alzabo::Runtime::UniqueRowCache> class.

=head1 METHODS

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

=head1 AUTHOR

Dave Rolsky, <autarch@urth.org>

=cut