summaryrefslogtreecommitdiff
path: root/lib/Variable/Disposition.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Variable/Disposition.pm')
-rw-r--r--lib/Variable/Disposition.pm40
1 files changed, 20 insertions, 20 deletions
diff --git a/lib/Variable/Disposition.pm b/lib/Variable/Disposition.pm
index 98b2847..fea0ea6 100644
--- a/lib/Variable/Disposition.pm
+++ b/lib/Variable/Disposition.pm
@@ -5,16 +5,12 @@ use warnings;
use parent qw(Exporter);
-our $VERSION = '0.004';
+our $VERSION = '0.005';
=head1 NAME
Variable::Disposition - helper functions for disposing of variables
-=head1 VERSION
-
-version 0.004
-
=head1 SYNOPSIS
use feature qw(say);
@@ -55,8 +51,8 @@ added later.
our @EXPORT_OK = qw(dispose retain retain_future);
our %EXPORT_TAGS = (
- all => [ @EXPORT_OK ],
- v1 => [ qw(dispose retain retain_future) ],
+ all => [ @EXPORT_OK ],
+ v1 => [ qw(dispose retain retain_future) ],
);
our @EXPORT = qw(dispose);
@@ -94,12 +90,12 @@ on scalar variables. To clear multiple variables, use a L<foreach> loop:
=cut
sub dispose($) {
- die "Variable not defined" unless defined $_[0];
- die "Variable was not a ref" unless ref $_[0];
- delete $RETAINED{$_[0]}; # just in case we'd previously retained this one
- Scalar::Util::weaken(my $copy = $_[0]);
- undef $_[0];
- die "Variable was not released" if defined $copy;
+ die "Variable not defined" unless defined $_[0];
+ die "Variable was not a ref" unless ref $_[0];
+ delete $RETAINED{$_[0]}; # just in case we'd previously retained this one
+ Scalar::Util::weaken(my $copy = $_[0]);
+ undef $_[0];
+ die "Variable was not released" if defined $copy;
}
=head2 retain
@@ -111,10 +107,10 @@ Returns the original variable.
=cut
sub retain($) {
- die "Variable not defined" unless defined $_[0];
- die "Variable was not a ref" unless ref $_[0];
- $RETAINED{$_[0]} = $_[0];
- $_[0]
+ die "Variable not defined" unless defined $_[0];
+ die "Variable was not a ref" unless ref $_[0];
+ $RETAINED{$_[0]} = $_[0];
+ $_[0]
}
=head2 retain_future
@@ -123,14 +119,17 @@ Holds a copy of the given L<Future> until it's marked ready, then releases our c
Does not use L</dispose>, since that could interfere with other callbacks attached
to the L<Future>.
+Since Future 0.36, this behaviour is directly available via the L<Future/retain> method,
+so it is recommended to use that instead of this function.
+
Returns the original L<Future>.
=cut
sub retain_future {
- my ($f) = @_;
- die "Variable does not seem to be a Future, since it has no ->on_ready method" unless $f->can('on_ready');
- $f->on_ready(sub { undef $f });
+ my ($f) = @_;
+ die "Variable does not seem to be a Future, since it has no ->on_ready method" unless $f->can('on_ready');
+ return $f->retain;
}
1;
@@ -154,3 +153,4 @@ Tom Molesworth <cpan@perlsite.co.uk>
=head1 LICENSE
Copyright Tom Molesworth 2014-2015. Licensed under the same terms as Perl itself.
+