```{index} single: Event::var ``` # Event::var ```{pperl-module-badges} Event::var ``` A var watcher: an event whenever a scalar variable is written to, or read. Its events are `Event::Event::Io` objects, whose `got` is `w` for a write and `r` for a read. `Event->var(%attributes)` (or `Event::var->new(...)`) takes the shared attributes of `Event::Watcher` and the ones below. A var watcher repeats; its default priority is `PRIO_NORMAL`. It refuses to start without a callback, without a variable ("watching what?"), with an empty `poll`, or on a read-only variable. Perl reads variables in more places than are apparent from the source, so watching reads is rarely what is wanted; the default is to watch writes only. ## Synopsis ```perl use Event; my $status = 'idle'; Event->var(var => \$status, cb => sub { print "status: $status\n" }); Event->timer(after => 1, cb => sub { $status = 'busy' }, repeat => 0); Event::loop(2); ``` ## Functions ### Attributes #### `var` The variable, as a reference to a plain scalar. A reference to an array, hash or anything else beyond a scalar dies "Var watchers can only watch plain vanilla scalars", and a value that is no reference dies "Expecting a reference". The watcher keeps the reference it was given. #### `poll` What to watch for: `"w"` (writes, the default), `"r"` (reads) or `"rw"`, or the number made of the bits `R` and `W` (see `Event::Watcher`). The value returned is both the string and the number.