#!/usr/bin/perl -w # # Test of Alarm::Concurrent - Written by Cory Johns (c) 2001 # ++$|; BEGIN { # This will be saved and activated when # Alarm::Concurrent is imported. alarm(1); $SIG{ALRM} = sub { print "Legacy alarm." }; } use Alarm::Concurrent qw( :OVERLOAD :ALL ); setalarm(6, sub { print "BONG!!!" }); alarm(2); sethandler(sub { print "bing" }); MyPack::doalarm(); # Alarms set for the same time go # off in the order you set them. setalarm(4, sub { print "!" }); package MyPack; sub doalarm { # Alarm is overridden in _all_ namespaces. alarm(4); # $SIG{ALRM} has been taken over. # It now calls sethandler(). $SIG{ALRM} = sub { print "bong" }; } #*******************************************# package main; for(1..6) { print "Second $_... "; sleep 1; print "\n"; }