File Coverage

blib/lib/EntityModel/EventLoop/Perl.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package EntityModel::EventLoop::Perl;
2             {
3             $EntityModel::EventLoop::Perl::VERSION = '0.001';
4             }
5             # ABSTRACT: Pure-Perl event loop implementation
6             use EntityModel::Class {
7 3         28 _isa => [qw(EntityModel::EventLoop)],
8 3     3   50826 };
  3         166759  
9 3     3   1006 use Time::HiRes ();
  3         6  
  3         407  
10              
11             =head1 NAME
12              
13             EntityModel::EventLoop::Perl - basic Perl implementation for EntityModel 'event loop'
14              
15             =head1 VERSION
16              
17             version 0.001
18              
19             =head1 DESCRIPTION
20              
21             Used only for testing in the absence of a real event loop.
22              
23             =head1 METHODS
24              
25             =cut
26              
27             =head2 defer
28              
29             'Defers' execution of the given codeblock. Actually does nothing of the sort, it just runs the
30             code immediately.
31              
32             =cut
33              
34             sub defer {
35 1     1 1 987 my $self = shift;
36 1         3 my $code = shift;
37 1         6 $code->();
38 1         543 $self;
39             }
40              
41             =head2 sleep
42              
43             Runs the given code block after an interval. Blocks execution until the timer expires.
44              
45             Instance method which expects an interval (in seconds) and a single coderef.
46              
47             =cut
48              
49             sub sleep {
50 1     1 1 969 my $self = shift;
51 1         2 my ($interval, $code) = @_;
52 1         50359 Time::HiRes::sleep $interval;
53 1         139 $code->();
54 1         11170 return $self;
55             }
56              
57             1;
58              
59             __END__