Revision 07d690e4
Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt
SL/DB/Object.pm | ||
---|---|---|
9 | 9 |
use SL::DB::Helper::Attr; |
10 | 10 |
use SL::DB::Helper::Metadata; |
11 | 11 |
use SL::DB::Helper::Manager; |
12 |
use SL::DB::Object::Hooks; |
|
12 | 13 |
|
13 | 14 |
use base qw(Rose::DB::Object); |
14 | 15 |
|
... | ... | |
94 | 95 |
return $check ? $self->$sub(@_) : $self; |
95 | 96 |
} |
96 | 97 |
|
98 |
# These three functions cannot sit in SL::DB::Object::Hooks because |
|
99 |
# mixins don't deal well with super classes (SUPER is the current |
|
100 |
# package's super class, not $self's). |
|
101 |
sub load { |
|
102 |
my ($self, @args) = @_; |
|
103 |
|
|
104 |
SL::DB::Object::Hooks::run_hooks($self, 'before_load'); |
|
105 |
my $result = $self->SUPER::load(@args); |
|
106 |
SL::DB::Object::Hooks::run_hooks($self, 'after_load', $result); |
|
107 |
|
|
108 |
return $result; |
|
109 |
} |
|
110 |
|
|
111 |
sub save { |
|
112 |
my ($self, @args) = @_; |
|
113 |
my $worker = sub { |
|
114 |
SL::DB::Object::Hooks::run_hooks($self, 'before_save'); |
|
115 |
my $result = $self->SUPER::save(@args); |
|
116 |
SL::DB::Object::Hooks::run_hooks($self, 'after_save', $result); |
|
117 |
}; |
|
118 |
|
|
119 |
return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
|
120 |
} |
|
121 |
|
|
122 |
sub delete { |
|
123 |
my ($self, @args) = @_; |
|
124 |
my $worker = sub { |
|
125 |
SL::DB::Object::Hooks::run_hooks($self, 'before_delete'); |
|
126 |
my $result = $self->SUPER::delete(@args); |
|
127 |
SL::DB::Object::Hooks::run_hooks($self, 'after_delete', $result); |
|
128 |
}; |
|
129 |
|
|
130 |
return $self->db->in_transaction ? $worker->() : $self->db->do_transaction($worker); |
|
131 |
} |
|
132 |
|
|
97 | 133 |
1; |
98 | 134 |
|
99 | 135 |
__END__ |
Auch abrufbar als: Unified diff
Framework für after/before-Hooks bei load/save/delete
Conflicts: