Or if, like most geeks, you have an aversion to a visible tie, you can make the interface much cleaner with:
use Attribute::Handlers;
use Tie::Cycle;
sub UNIVERSAL::Spinner : ATTR(SCALAR) {
tie ${$_[2]},
'Tie::Cycle',
[map $_."\b" x length, @{$_[4]||[qw(\ | / -)]}]
}
And then whip up custom spinners very elegantly, as the need arises:
$|=1;
my $spinner : Spinner;
print $spinner for (1..10000);
my $morse_blinker : Spinner( qw(! : .) );
print $morse_blinker for (1..10000);
my $wobbler : Spinner( "\)", "\(" );
print $wobbler for (1..10000);
my $flexer : Spinner( '< ', ' >' );
print $flexer for (1..10000);