The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Ryu::Observable - plus ça change

DESCRIPTION

This is by way of being a thing that lets you set up subscriptions on things so that you can be notified when said things are in some way not the same as the things they used to be, but are indeed now possessed of some detectable difference which may be of relevance to the thing that makes use of this thing which notifies as per the aforementioned conditions.

METHODS

Public API, such as it is.

as_string

Returns the string representation of this value.

as_number

Returns the numeric representation of this value.

new

Instantiates with the given value.

 my $observed = Ryu::Observable->new('whatever');

subscribe

Requests notifications when the value changes.

 my $observed = Ryu::Observable->new('whatever')
   ->subscribe(sub { print "New value - $_\n" });

unsubscribe

Removes an existing callback.

 my $code;
 my $observed = Ryu::Observable->new('whatever')
   ->subscribe($code = sub { print "New value - $_\n" })
   ->set_string('test')
   ->unsubscribe($code);

set

Sets the value to the given scalar, then notifies all subscribers (regardless of whether the value has changed or not).

value

Returns the raw value.

set_numeric

Applies a new numeric value, and notifies subscribers if the value is numerically different to the previous one (or if we had no previous value).

Returns $self.

set_string

Applies a new string value, and notifies subscribers if the value stringifies to a different value than the previous one (or if we had no previous value).

Returns $self.

source

Returns a Ryu::Source, which will emit each new value until the observable is destroyed.

METHODS - Internal

Don't use these.

notify_all

Notifies all currently-subscribed callbacks with the current value.

AUTHOR

Tom Molesworth <TEAM@cpan.org>

LICENSE

Copyright Tom Molesworth 2011-2019. Licensed under the same terms as Perl itself.