Tie::Scalar::Callback - a tied scalar which executes a callback everytime it is used
version 0.07
use Tie::Scalar::Callback; # this coderef doubles the scalar's value everytime it's fetched my $coderef = sub { state $value = 1/2; state $factor = 2; $value *= $factor; } }; tie(my $doubler, 'Tie::Scalar::Callback', $coderef); print $doubler; 1 print $doubler; 2 print $doubler; 4
Tie::Scalar::Callback is a class for creating tied scalars which execute a callback everytime an event occurs on the scalar. The callback's return value becomes the scalar's apparent value.
Tie::Scalar::Callback
Thanks to brian d foy for coming up with the idea for this module.
Tie::Simple
Tie::Cycle
Tie::Scalar::Decay
Tie::Scalar::Ratio
David Farrell <dfarrell@cpan.org>
This software is Copyright (c) 2016 by David Farrell.
This is free software, licensed under:
The (two-clause) FreeBSD License
To install Tie::Scalar::Callback, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Scalar::Callback
CPAN shell
perl -MCPAN -e shell install Tie::Scalar::Callback
For more information on module installation, please visit the detailed CPAN module installation guide.