File Coverage

blib/lib/Alzabo/Runtime/RowState/InCache.pm
Criterion Covered Total %
statement 13 34 38.2
branch 0 6 0.0
condition n/a
subroutine 4 10 40.0
pod 0 3 0.0
total 17 53 32.0


line stmt bran cond sub pod time code
1             package Alzabo::Runtime::RowState::InCache;
2              
3 2     2   18 use strict;
  2         4  
  2         127  
4              
5 2     2   13 use base qw(Alzabo::Runtime::RowState::Live);
  2         5  
  2         234  
6              
7             BEGIN
8             {
9 2     2   11 no strict 'refs';
  2         4  
  2         285  
10 2     2   13 foreach my $meth ( qw( select select_hash ) )
11             {
12 4         10 my $super = "SUPER::$meth";
13 4         683 *{__PACKAGE__ . "::$meth"} =
14 0     0     sub { my $s = shift;
15              
16 0 0         $s->refresh(@_) unless $s->_in_cache(@_);
17              
18 0           $s->$super(@_);
19 4         20 };
20             }
21             }
22              
23             sub update
24             {
25 0     0 0   my $class = shift;
26 0           my $row = shift;
27              
28 0           my $old_id = $row->id_as_string;
29              
30 0 0         $class->refresh($row) unless $class->_in_cache($row);
31              
32 0           my $changed = $class->SUPER::update( $row, @_ );
33              
34 0 0         return $changed if exists $row->{id_string};
35              
36 0           Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );
37              
38 0           Alzabo::Runtime::UniqueRowCache->write_to_cache($row);
39              
40 0           return $changed;
41             }
42              
43             sub delete
44             {
45 0     0 0   my $class = shift;
46 0           my $row = shift;
47              
48 0           my $old_id = $row->id_as_string;
49              
50 0           $class->SUPER::delete( $row, @_ );
51              
52 0           Alzabo::Runtime::UniqueRowCache->delete_from_cache( $row->table->name, $old_id );
53             }
54              
55             sub refresh
56             {
57 0     0 0   my $class = shift;
58              
59 0           $class->SUPER::refresh(@_);
60              
61             # return if $class->_in_cache($row); #????
62             }
63              
64             sub _in_cache
65             {
66             return
67 0     0     Alzabo::Runtime::UniqueRowCache->row_in_cache
68             ( $_[1]->table->name, $_[1]->id_as_string );
69             }
70              
71             sub _write_to_cache
72             {
73 0     0     Alzabo::Runtime::UniqueRowCache->write_to_cache( $_[1] );
74             }
75              
76              
77             1;
78              
79             __END__