Ryu::Observable(3)

πŸ“¦ version 4.001, in alpine 3.24

✨ 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 require Sentinel to be installed ⚠️ like, no Sentinel, 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