/[cvs]/joko/TestArea/perl/runtime/POE/jobs-tasks/followtail.pl
ViewVC logotype

Annotation of /joko/TestArea/perl/runtime/POE/jobs-tasks/followtail.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sun May 11 21:48:52 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
initial commit

1 joko 1.1
2     #sub POE::Kernel::ASSERT_DEFAULT () { 1 }
3     #sub POE::Kernel::TRACE_DEFAULT () { 1 }
4    
5     use POE qw ( Wheel::FollowTail Driver::SysRW Filter::Line Filter::Stream );
6     use IO::File;
7    
8     my $input_event_name = 'got_input';
9     my $error_event_name = 'got_error';
10     my $reset_event_name = 'got_reset';
11     my $offset = 0;
12    
13     sub _start {
14     my ($kernel, $session, $heap) = @_[ KERNEL, SESSION, HEAP ];
15    
16     $file_name = 'c:\var\home\amo\.mjamcmd';
17    
18     if (!-f $file_name) {
19     open(FH, '>' . $file_name);
20     print FH "hello world", "\n";
21     close(FH);
22     }
23    
24     #my $file_handle;
25     #open($file_handle, '<' . $file_name);
26     my $file_handle = IO::File->new("<$file_name");
27    
28     $heap->{wheel} = POE::Wheel::FollowTail->new(
29     #Filename => $file_name, # File to tail
30     Handle => $file_handle, # File to tail
31     Driver => POE::Driver::SysRW->new(), # How to read it
32     Filter => POE::Filter::Line->new(), # How to parse it
33     PollInterval => 1, # How often to check it
34     InputEvent => $input_event_name, # Event to emit upon input
35     ErrorEvent => $error_event_name, # Event to emit upon error
36     #ResetEvent => $reset_event_name, # Event to emit on file reset
37     #SeekBack => $offset, # How far from EOF to start
38     );
39     }
40    
41     sub _stop {
42     print "stopped", "\n";
43     }
44    
45     sub got_input {
46     print "====== input", "\n";
47     }
48     sub got_error {
49     print "====== error", "\n";
50     }
51     sub got_reset {
52     print "====== reset", "\n";
53     }
54    
55     my @handlers = qw(
56     _start
57     _stop
58     got_input
59     got_error
60     got_reset
61     );
62    
63     # the main session for the query-agent
64     POE::Session->create(
65     package_states => [ main => \@handlers ],
66     );
67    
68     POE::Session->new
69     ( _start => sub
70     { my ($kernel, $session) = @_[KERNEL, SESSION];
71     $kernel->post($session, 'spin a wheel');
72     },
73     'spin a wheel' => sub
74     { my $kernel = $_[KERNEL];
75     print "*** spin! ***\n";
76     $kernel->delay('spin a wheel', 0.5);
77     },
78     );
79    
80     $poe_kernel->run();

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed