diff options
author | mateu <mateu@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-28 13:16:29 +0000 |
---|---|---|
committer | mateu <mateu@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2009-07-28 13:16:29 +0000 |
commit | b4e081f82ee3491636b87a027e8eee2533b520f1 (patch) | |
tree | 6e43ffccc49c1e3004c08888354087bc87bba1c7 /lib/Reaction/UI/Controller.pm | |
parent | 20d63b20fd2d6d545279e810825ce66227a10229 (diff) | |
download | reaction-b4e081f82ee3491636b87a027e8eee2533b520f1.tar.gz reaction-b4e081f82ee3491636b87a027e8eee2533b520f1.zip |
Document make_context_closure().
Diffstat (limited to 'lib/Reaction/UI/Controller.pm')
-rw-r--r-- | lib/Reaction/UI/Controller.pm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Controller.pm b/lib/Reaction/UI/Controller.pm index d5c2b28..46456bd 100644 --- a/lib/Reaction/UI/Controller.pm +++ b/lib/Reaction/UI/Controller.pm @@ -184,6 +184,45 @@ controller. $captures and $args default to the current requests $captures and $args if not supplied. +=head2 make_context_closure + +The purpose of this method is to prevent memory leaks. +It weakens the context object, often denoted $c, and passes it as the +first argument to the sub{} that is passed to the make_context_closure method. +In other words, + +=over 4 + +make_context_closure returns sub { $sub_you_gave_it->($weak_c, @_) + +=back + +To further expound up this useful construct consider code written before +make_context_closure was created: + + on_apply_callback => + sub { + $self->after_search( $c, @_ ); + } + ), + +This could be rewritten as: + + on_apply_callback => $self->make_context_closure( + sub { + my $weak_c = shift; + $self->after_search( $weak_c, @_ ); + } + ), + +Or even more succintly: + + on_apply_callback => $self->make_context_closure( + sub { + $self->after_search( @_ ); + } + ), + =head1 AUTHORS See L<Reaction::Class> for authors. |