my $loop_class = _get_loop_class() ;
-init_loop() ;
+INIT{ init_loop() ; }
sub init_loop {
+Stem::Event::Queue::_init_queue() if defined &Stem::Event::Queue::_init_queue ;
+
$loop_class->_init_loop() ;
-Stem::Event::Queue::_init_queue() if defined &Stem::Event::Queue::_init_queue ;
}
$loop_type = 'perl' unless $loop_to_class{ $loop_type } ;
my $loop_class = "Stem::Event::$loop_to_class{ $loop_type }" ;
+print "LOOP $loop_class\n" ;
+
unless ( eval "require $loop_class" ) {
die "can't load $loop_class: $@" if $@ && $@ !~ /locate/ ;
+print "not found\n" ;
+
$loop_type = 'perl' ;
eval { require Stem::Event::Perl } ;
die "can't load event loop Stem::Event::Perl $@" if $@ ;
}
+
# save the event loop that we loaded.
#print "using event loop [$loop_type]\n" ;
$Stem::Vars::Env{ 'event_loop' } = $loop_type ;
+
return $loop_class ;
}
############################################################################
package Stem::Event::Plain ;
-
-BEGIN {
- @Stem::Event::Plain::ISA = qw( Stem::Event ) ;
-}
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Plain::new
my $self = Stem::Class::parse_args( $attr_spec_plain, @_ ) ;
return $self unless ref $self ;
- my $err = $self->_core_event_build( 'plain' ) ;
+ my $err = $self->_build_core_event( 'plain' ) ;
return $err if $err ;
return $self ;
############################################################################
package Stem::Event::Signal ;
-
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Signal::new
############################################################################
package Stem::Event::Timer ;
-
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
=head2 Stem::Event::Timer::new
# these override Stem::Event's methods and then call those via SUPER::
package Stem::Event::IO ;
-
-BEGIN { our @ISA = qw( Stem::Event ) } ;
+our @ISA = qw( Stem::Event ) ;
sub init_io_timeout {
#######################################################
package Stem::Event::Read ;
+our @ISA = qw( Stem::Event::IO ) ;
+print "B @ISA\n" ;
-BEGIN { our @ISA = qw( Stem::Event::IO ) }
=head2 Stem::Event::Read::new
sub new {
my( $class ) = shift ;
+print "@ISA\n" ;
my $self = Stem::Class::parse_args( $attr_spec_read, @_ ) ;
return $self unless ref $self ;
+
# return <<ERR unless defined fileno $self->{fh} ;
# Stem::Event::Read: $self->{fh} is not an open handle
# ERR
############################################################################
package Stem::Event::Write ;
-
-BEGIN { our @ISA = qw( Stem::Event::IO ) } ;
+our @ISA = qw( Stem::Event::IO ) ;
=head2 Stem::Event::Write::new
use strict ;
-#use Test::More tests => 29 ;
-use Test::More tests => 24 ;
+use Test::More tests => 27 ;
use Symbol ;
sub test_events {
-# test_null_events() ;
-# test_plain_events () ;
-# test_signal_events () ;
+ test_null_events() ;
+ test_plain_events () ;
+ test_signal_events () ;
test_hard_timer_events () ;
test_soft_timer_events () ;
test_io_events () ;
my( $self ) = @_ ;
ok( 1, 'plain event triggered' ) ;
+ Stem::Event::stop_loop() ;
}
sub test_signal_events {
return ;
}
+ my $event2 = Stem::Event::Timer->new(
+ 'object' => $self,
+ 'method' => 'send_int_signal',
+ 'delay' => 3,
+ ) ;
+
+ ok( ref $event2, 'signal delay timer created' ) ;
+
+ Stem::Event::start_loop() ;
+
+ ok( 1, 'signal - event loop exit' ) ;
+ }
+}
+
+sub send_int_signal {
+
my $event = Stem::Event::Signal->new(
'object' => $self,
'signal' => 'INT',
$self->{'sig_event'} = $event ;
- kill 'INT', $$ ;
-
-#print "kill INT\n" ;
- Stem::Event::start_loop() ;
+print "kill INT\n" ;
- ok( 1, 'signal - event loop exit' ) ;
- }
+ kill 'INT', $$ ;
}
# callback method for signal
my( $self ) = @_ ;
+send_int_signal() ;
+
ok( 1, 'hard timer event triggered' ) ;
if ( --$self->{'hard_timer_count'} > 0 ) {