package Timer;

sub TIESCALAR { bless \time, shift }
sub FETCH { time - ${+shift} }
sub STORE { ${+shift} = pop }

sub FETCH_SCALAR_ATTRIBUTES {
  my $class = shift;
  return qw( Timer );
}

sub MODIFY_SCALAR_ATTRIBUTES {
  my $class = shift;
  my $ref = shift;
  my @unhandled;

  for my $attr (@_) {
    if ($attr eq 'Timer') {
      tie $$ref, 'Timer';
    }
    else {
      push @unhandled, $attr;
    }
  }

  return @unhandled;
}

1;
