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