Devel-WatchVars
view release on metacpan or search on metacpan
lib/Devel/WatchVars.pm view on Meta::CPAN
=encoding utf8
=cut
use utf8;
use strict;
use warnings;
no overloading;
use Carp;
use Scalar::Util qw(weaken readonly reftype);
use namespace::clean;
###########################################################
our $VERSION = "v1.0.5";
use Exporter qw(import);
our @EXPORT = qw(watch unwatch);
lib/Devel/WatchVars.pm view on Meta::CPAN
$reftype =~ /^(?:SCALAR|REF)\z/ ||
croak "You didn't pass a SCALAR (by reference), you passed a ",
$reftype ? "$reftype (by reference)"
: defined($sref) ? "non-reference"
: "undef";
!readonly($$sref) || croak "Can't watch a readonly scalar";
my $value = $$sref;
my $self = tie $$sref, $TIE_PACKAGE, $name, $value;
weaken($$self{sref} = $sref);
}
###########################################################
sub unwatch(\$) {
my($tref) = @_;
ref($tref) eq "SCALAR" || croak "You didn't pass a scalar (by reference)";
my $self = tied $$tref || croak "Can't unwatch something that isn't tied";
$self->isa($TIE_PACKAGE) || croak "Can't unwatch something that isn't watched";
my($sref, $value) = @$self{sref => "value"};
( run in 0.725 second using v1.01-cache-2.11-cpan-65fba6d93b7 )