NAME
MoobX::Observer - a MoobX object reacting to observable variable changes
VERSION
version 0.1.2
SYNOPSIS
use MoobX;
use MoobX::Observer;
observable( my $foo = 'hi' );
my $obs = MoobX::Observer->new(
generator => sub { scalar reverse $foo }
);
$foo = 'hello';
say $obs; # prints 'olleh'
DESCRIPTION
This class implements the observer object used by MoobX.
OVERLOADED OPERATIONS
MoobX::Observer objects are stringified using their value
attribute.
METHODS
new
my $obs = MoobX::Observer->new(
generator => sub { ... },
autorun => 1,
);
Constructor. Accepts two arguments:
- generator
-
Function generating the observer value. Required.
- autorun
-
If set to true, the observer will eagerly compute its value at creation time, and recompute it as soon as a dependency changes. Defaults to
false
.
value
Returns the currently cached observer's value.
AUTHOR
Yanick Champoux <yanick@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2022, 2017 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.