Ryu::Observable(3)
β¨ Ryu::Observable β¨
ok so this is Ryu::Observable(3) from the User Contributed Perl Documentation section, and bestie, it's literally "plus Γ§a change" β that's the whole vibe, the more things change the more they stay the same π
πΈ NAME πΈ
Ryu::Observable β plus Γ§a change π¦
π SYNOPSIS π
# Set initial value
my $observed = Ryu::Observable->new(123)
# and a callback for any changes
->subscribe(sub { print "New value, is now: $_\n" });
# Basic numeric increment/decrement should trigger a notification
++$observed;
# To assign a new value, use ->set_numeric or ->set_string
$observed->set_numeric(88);
like, that's it. that's the whole flex. β¨
π DESCRIPTION π
Simple monitorable variables. no cap, that's genuinely all this is β lil variables you can keep an eye on π and they'll ping you the second something changes. main character energy fr.
π METHODS π
Public API, such as it is π«Ά
π as_string
Returns the string representation of this value π¬
π¦ as_number / as_numeric
Returns the numeric representation of this value π’
(this method is available as as_number or as_numeric, both operate the same way β pick whichever one your brain likes, they're literally twins)
π new
Instantiates with the given value β¨
my $observed = Ryu::Observable->new('whatever');
πΈ subscribe
Requests notifications when the value changes π¬ like, you're officially on the list now
my $observed = Ryu::Observable->new('whatever')
->subscribe(sub { print "New value - $_\n" });
π unsubscribe
Removes an existing callback πͺβοΈ no hard feelings
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) π£ like yes you're getting the notification even if it's the same value, that's the deal, periodt.
β value
Returns the raw value π
π₯ set_numeric / set_number
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 π«
(this method is available as set_number or set_numeric, both operate the same way β again, twinsies, choose your fighter)
π 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 π like a lil stream of your values, iconic
π LVALUE METHODS π
These requireSentinelto be installed β οΈ like, noSentinel, no lvalue magic, sorry bestie π
πΈ lvalue_str
Returns a Sentinel lvalue accessor for the string value π€
This can be used with refaliasing or foreach loops to reduce typing:
for($observable->lvalue_str) {
chomp;
s/_/-/g;
}
Any attempt to retrieve or set the value will be redirected to as_string or set_string as appropriate π―
π lvalue_num
Returns a Sentinel lvalue accessor for the numeric value π’
This can be used with refaliasing or foreach loops to reduce typing:
for($observable->lvalue_num) {
++$_;
$_ *= 3;
}
Any attempt to retrieve or set the value will be redirected to as_number or set_number as appropriate π―
π§ finish
Mark this observable as finished π
No further events or notifications will be sent π«π¬ like, that's it, we're done, the group chat is archived.
π METHODS - Internal π
Don't use these. fr fr. i'm serious. don't. π
π
notify_all
Notifies all currently-subscribed callbacks with the current value π£
π AUTHOR π
Tom Molesworth "<TEAM@cpan.org>" π«Ά
π LICENSE π
Copyright Tom Molesworth 2011-2024. Licensed under the same terms as Perl itself. π
and that's a wrap β¨ this was Ryu::Observable(3) from perl v5.42.2, dated 2026-02-15 β go forth and observe your variables bestie, you're gonna slay πππ¦
π¦ where this page comes from
- alpine 3.24: perl-ryu-doc 4.001-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms