| 1 | package IPC::Transit::Test::Example; | ||
| 2 | $IPC::Transit::Test::Example::VERSION = '1.162230'; | ||
| 3 | use strict;use warnings; | ||
| 4 | use Data::Dumper; | ||
| 5 | use IPC::Transit; | ||
| 6 | use POE; | ||
| 7 | use JSON; | ||
| 8 | use File::Slurp; | ||
| 9 | |||
| 10 | sub | ||
| 11 | import { | ||
| 12 | my $self = shift; | ||
| 13 | my ($callpack, $callfile, $callline) = caller; | ||
| 14 | my @EXPORT; | ||
| 15 | if (@_) { | ||
| 16 | @EXPORT = @_; | ||
| 17 | } | ||
| 18 | foreach my $sym (@EXPORT) { | ||
| 19 | no strict 'refs'; | ||
| 20 | *{"${callpack}::$sym"} = \&{"IPC::Transit::Test::Example::$sym"}; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | sub | ||
| 25 | get_routes { | ||
| 26 | my $routes_text = read_file('routes.json') or die "get_routes: routes.json not found\n"; | ||
| 27 | my $routes; | ||
| 28 | eval { | ||
| 29 | $routes = decode_json($routes_text) or die "returned false\n"; | ||
| 30 | }; | ||
| 31 | die "get_routes: decode_json() failed: $@\n" if $@; | ||
| 32 | return $routes; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub | ||
| 36 | recur { | ||
| 37 | my %args = @_; | ||
| 38 | |||
| 39 | $args{repeat} = 300 unless $args{repeat}; | ||
| 40 | $args{work} = sub { print "Somebody forgot to pass work\n"; } unless $args{work}; | ||
| 41 | POE::Session->create( | ||
| 42 | inline_states => { | ||
| 43 | _start => sub {$_[KERNEL]->delay(tick => 1);}, | ||
| 44 | tick => sub { | ||
| 45 | $_[KERNEL]->delay(tick => $args{repeat}); | ||
| 46 | &{$args{work}}(\%args); | ||
| 47 | }, | ||
| 48 | _child => sub { }, #ignore kids | ||
| 49 | }, | ||
| 50 | ); | ||
| 51 | } | ||
| 52 | |||
| 53 | 1; |