Callback-Cleanup
view release on metacpan or search on metacpan
---
name: Callback-Cleanup
version: 0.03
author:
- 'Yuval Kogman <nothingmuch@woobling.org>'
abstract: Declare callbacks that clean themselves up
license: perl
resources:
license: http://dev.perl.org/licenses/
requires:
Hash::Util::FieldHash::Compat: 0
Sub::Clone: 0
Sub::Exporter: 0
ok: 0
provides:
Callback::Cleanup:
NAME
Callback::Cleanup - Declare callbacks that clean themselves up
SYNOPSIS
use Callback::Cleanup;
my $anon_sub = callback {
# this is the sub body
} cleanup {
# this is called on DESTROY
}
# or
Callback::Cleanup->new(
sub { }, # callback
sub { }, # cleanup
);
DESCRIPTION
This is a very simple module that provides syntactic sugar for callbacks
that need to finalize somehow.
Callbacks are very convenient APIs when they have no definite end of
life. If an end of life behavior is required this helps keep the cleanup
code and callback code together.
EXPORTS
callback BLOCK $cleanup
cleanup BLOCK $callback
Both of these exports act as the identity function when given only
} \&needs_cleanup;
As well as a few other useless forms.
CLOSURES AND GARBAGE COLLECTION
In perl code references that are not closures aren't garbage collected
(they are shared).
This module uses "clone_if_immortal" in Sub::Clone to make sure timely
destruction of these callbacks happens.
AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
COPYRIGHT & LICENSE
Copyright (c) 2006, 2008 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
lib/Callback/Cleanup.pm view on Meta::CPAN
sub DESTROY { delete($cleanups{$_[0]})->() }
__PACKAGE__;
__END__
=pod
=head1 NAME
Callback::Cleanup - Declare callbacks that clean themselves up
=head1 SYNOPSIS
use Callback::Cleanup;
my $anon_sub = callback {
# this is the sub body
} cleanup {
# this is called on DESTROY
}
# or
Callback::Cleanup->new(
sub { }, # callback
sub { }, # cleanup
);
=head1 DESCRIPTION
This is a very simple module that provides syntactic sugar for callbacks that
need to finalize somehow.
Callbacks are very convenient APIs when they have no definite end of life. If
an end of life behavior is required this helps keep the cleanup code and
callback code together.
=head1 EXPORTS
=over 4
lib/Callback/Cleanup.pm view on Meta::CPAN
As well as a few other useless forms.
=back
=head1 CLOSURES AND GARBAGE COLLECTION
In perl code references that are not closures aren't garbage collected (they
are shared).
This module uses L<Sub::Clone/clone_if_immortal> to make sure timely
destruction of these callbacks happens.
=head1 AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2006, 2008 the aforementioned authors. All rights
reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
( run in 0.764 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )