An open API service indexing awesome lists of open source software.

https://github.com/dnmfarrell/tie-scalar-callback

A scalar which executes a callback every time is used
https://github.com/dnmfarrell/tie-scalar-callback

Last synced: over 1 year ago
JSON representation

A scalar which executes a callback every time is used

Awesome Lists containing this project

README

          

=pod

=encoding UTF-8

=head1 NAME

Tie::Scalar::Callback - a tied scalar which executes a callback everytime it is used

=head1 VERSION

version 0.062

=head1 SYNOPSIS

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

=head1 DESCRIPTION

C 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.

=head1 ACKNOWLEDGEMENTS

Thanks to L for coming up with the idea for this module.

=head1 SEE ALSO

=over 4

=item *

L

=item *

L

=item *

L

=back

=head1 AUTHOR

David Farrell

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by David Farrell.

This is free software, licensed under:

The (two-clause) FreeBSD License

=cut