3 # A package for manipulating SDL_Timer *
5 # Copyright (C) 2002 David J. Goehrig
15 my $class = ref($proto) || $proto;
20 verify(%options,qw/ -delay -times -d -t /);
22 croak "SDL::Timer::new no delay specified\n"
23 unless ($options{-delay});
24 $$self{-delay} = $options{-delay} || $options{-d} || 0;
25 $$self{-times} = $options{-times} || $options{-t} || 0;
27 $$self{-routine} = sub { &$func($self); $$self{-delay} if(--$$self{-times}) };
29 $$self{-routine} = sub { &$func; $$self{-delay}};
31 $$self{-timer} = SDL::NewTimer($$self{-delay},$$self{-routine});
32 croak "Could not create timer, ", SDL::GetError(), "\n"
33 unless ($self->{-timer});
40 SDL::RemoveTimer($$self{-timer}) if ($$self{-timer});
45 my ($self,$delay,$times) = @_;
46 $$self{-delay} = $delay;
47 $$self{-times} = $times;
48 SDL::RemoveTimer($$self{-timer}) if ($$self{-timer});
49 $$self{-timer} = SDL::AddTimer($$self{-delay},SDL::PerlTimerCallback,$$self{-routine});
54 SDL::RemoveTimer($$self{-timer}) if ($$self{-timer});
67 SDL::Timer - a SDL perl extension to handle timers
71 $timer = new SDL::Timer { print "tick"; 4000; } -delay => 4000;
75 C<SDL::Timer> provides an abstract interface to the SDL::Timer
76 callback code. SDL::Timer::new requires a subroutine and a delay
77 at which is the initial interval between the creation of the
78 timer until the first call to the subroutine. The subroutine
79 must return a value which is the delay until the it is called again.