| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package ZMQ::Raw::Loop::Timer; | 
| 2 |  |  |  |  |  |  | $ZMQ::Raw::Loop::Timer::VERSION = '0.37'; | 
| 3 | 14 |  |  | 14 |  | 75 | use strict; | 
|  | 14 |  |  |  |  | 26 |  | 
|  | 14 |  |  |  |  | 411 |  | 
| 4 | 14 |  |  | 14 |  | 71 | use warnings; | 
|  | 14 |  |  |  |  | 21 |  | 
|  | 14 |  |  |  |  | 478 |  | 
| 5 | 14 |  |  | 14 |  | 73 | use Scalar::Util qw/weaken/; | 
|  | 14 |  |  |  |  | 22 |  | 
|  | 14 |  |  |  |  | 503 |  | 
| 6 | 14 |  |  | 14 |  | 63 | use Carp; | 
|  | 14 |  |  |  |  | 17 |  | 
|  | 14 |  |  |  |  | 1237 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 0 |  |  | 0 |  | 0 | sub CLONE_SKIP { 1 } | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | my @attributes; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | BEGIN | 
| 13 |  |  |  |  |  |  | { | 
| 14 | 14 |  |  | 14 |  | 88 | @attributes = qw/ | 
| 15 |  |  |  |  |  |  | timer | 
| 16 |  |  |  |  |  |  | on_cancel | 
| 17 |  |  |  |  |  |  | on_timeout | 
| 18 |  |  |  |  |  |  | /; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 14 |  |  | 14 |  | 80 | no strict 'refs'; | 
|  | 14 |  |  |  |  | 23 |  | 
|  | 14 |  |  |  |  | 1032 |  | 
| 21 | 14 |  |  |  |  | 33 | foreach my $accessor (@attributes) | 
| 22 |  |  |  |  |  |  | { | 
| 23 | 42 |  |  |  |  | 391 | *{$accessor} = sub | 
| 24 |  |  |  |  |  |  | { | 
| 25 | 456 | 50 |  | 456 |  | 3805 | @_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor} | 
| 26 | 42 |  |  |  |  | 119 | }; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 14 |  |  | 14 |  | 80 | use ZMQ::Raw; | 
|  | 14 |  |  |  |  | 28 |  | 
|  | 14 |  |  |  |  | 5437 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head1 NAME | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | ZMQ::Raw::Loop::Timer - Timer class | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =head1 VERSION | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | version 0.37 | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | A L represents a timer, usable in a | 
| 43 |  |  |  |  |  |  | L. | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | B: The API of this module is unstable and may change without warning | 
| 46 |  |  |  |  |  |  | (any change will be appropriately documented in the changelog). | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | use ZMQ::Raw; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | my $context = ZMQ::Raw::Context->new; | 
| 53 |  |  |  |  |  |  | my $loop = ZMQ::Raw::Loop->new ($context); | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | my $timer = ZMQ::Raw::Loop::Timer->new | 
| 56 |  |  |  |  |  |  | ( | 
| 57 |  |  |  |  |  |  | timer => ZMQ::Raw::Timer->new ($context, after => 100), | 
| 58 |  |  |  |  |  |  | on_timeout => sub | 
| 59 |  |  |  |  |  |  | { | 
| 60 |  |  |  |  |  |  | print "Timed out!\n"; | 
| 61 |  |  |  |  |  |  | $loop->terminate(); | 
| 62 |  |  |  |  |  |  | }, | 
| 63 |  |  |  |  |  |  | on_cancel => sub | 
| 64 |  |  |  |  |  |  | { | 
| 65 |  |  |  |  |  |  | print "Cancelled!\n"; | 
| 66 |  |  |  |  |  |  | }, | 
| 67 |  |  |  |  |  |  | ); | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | $loop->add ($timer); | 
| 70 |  |  |  |  |  |  | $loop->run; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head1 METHODS | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head2 new( ) | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | Create a new loop timer. | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head2 cancel( ) | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | Cancel the underlying timer. | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head2 reset( ) | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | Reset the underlying timer. | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head2 expire( ) | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | Expire the underlying timer. | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head2 running( ) | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | Check if the timer is running. | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =cut | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub new | 
| 97 |  |  |  |  |  |  | { | 
| 98 | 13 |  |  | 13 | 1 | 75 | my ($this, %args) = @_; | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 13 | 50 | 33 |  |  | 88 | if (!$args{timer} || ref ($args{timer}) ne 'ZMQ::Raw::Timer') | 
| 101 |  |  |  |  |  |  | { | 
| 102 | 0 |  |  |  |  | 0 | croak "timer not provided or not a 'ZMQ::Raw::Timer'"; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 | 13 | 50 | 33 |  |  | 61 | if (!$args{on_timeout} || ref ($args{on_timeout}) ne 'CODE') | 
| 106 |  |  |  |  |  |  | { | 
| 107 | 0 |  |  |  |  | 0 | croak "on_timeout not a code ref"; | 
| 108 |  |  |  |  |  |  | } | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 13 | 50 | 66 |  |  | 65 | if ($args{on_cancel} && ref ($args{on_cancel}) ne 'CODE') | 
| 111 |  |  |  |  |  |  | { | 
| 112 | 0 |  |  |  |  | 0 | croak "on_cancel not a code ref"; | 
| 113 |  |  |  |  |  |  | } | 
| 114 |  |  |  |  |  |  |  | 
| 115 | 13 |  | 33 |  |  | 38 | my $class = ref ($this) || $this; | 
| 116 |  |  |  |  |  |  | my $self = | 
| 117 |  |  |  |  |  |  | { | 
| 118 |  |  |  |  |  |  | timer => $args{timer}, | 
| 119 |  |  |  |  |  |  | on_timeout => $args{on_timeout}, | 
| 120 |  |  |  |  |  |  | on_cancel => $args{on_cancel}, | 
| 121 | 13 |  |  |  |  | 45 | }; | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 13 |  |  |  |  | 134 | return bless $self, $class; | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | sub loop | 
| 129 |  |  |  |  |  |  | { | 
| 130 | 159 |  |  | 159 | 0 | 270 | my ($this, $loop) = @_; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 159 | 100 |  |  |  | 373 | if (scalar (@_) > 1) | 
| 133 |  |  |  |  |  |  | { | 
| 134 | 76 |  |  |  |  | 168 | $this->{loop} = $loop; | 
| 135 | 76 |  |  |  |  | 239 | weaken ($this->{loop}); | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 159 |  |  |  |  | 421 | return $this->{loop}; | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub cancel | 
| 144 |  |  |  |  |  |  | { | 
| 145 | 7 |  |  | 7 | 1 | 27 | my ($this) = @_; | 
| 146 |  |  |  |  |  |  |  | 
| 147 | 7 |  |  |  |  | 17 | $this->timer->cancel; | 
| 148 |  |  |  |  |  |  |  | 
| 149 | 7 | 50 |  |  |  | 31 | if ($this->loop) | 
| 150 |  |  |  |  |  |  | { | 
| 151 | 7 |  |  |  |  | 18 | $this->loop->remove ($this); | 
| 152 |  |  |  |  |  |  |  | 
| 153 | 7 | 100 |  |  |  | 20 | if ($this->on_cancel) | 
| 154 |  |  |  |  |  |  | { | 
| 155 | 1 |  |  |  |  | 2 | &{$this->on_cancel}(); | 
|  | 1 |  |  |  |  | 3 |  | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  | } | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | sub reset | 
| 163 |  |  |  |  |  |  | { | 
| 164 | 23 |  |  | 23 | 1 | 1261 | my ($this) = @_; | 
| 165 |  |  |  |  |  |  |  | 
| 166 | 23 |  |  |  |  | 71 | $this->timer->reset; | 
| 167 |  |  |  |  |  |  |  | 
| 168 | 23 | 50 |  |  |  | 103 | if ($this->loop) | 
| 169 |  |  |  |  |  |  | { | 
| 170 | 23 |  |  |  |  | 45 | $this->loop->remove ($this); | 
| 171 | 23 |  |  |  |  | 61 | $this->loop->add ($this); | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | } | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | sub expire | 
| 178 |  |  |  |  |  |  | { | 
| 179 | 1 |  |  | 1 | 1 | 7 | my ($this) = @_; | 
| 180 |  |  |  |  |  |  |  | 
| 181 | 1 |  |  |  |  | 3 | $this->timer->expire; | 
| 182 |  |  |  |  |  |  | } | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | sub running | 
| 187 |  |  |  |  |  |  | { | 
| 188 | 76 |  |  | 76 | 1 | 166 | my ($this) = @_; | 
| 189 |  |  |  |  |  |  |  | 
| 190 | 76 |  |  |  |  | 147 | return $this->timer->running; | 
| 191 |  |  |  |  |  |  | } | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =for Pod::Coverage timer loop on_cancel on_timeout | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | =head1 AUTHOR | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | Jacques Germishuys | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | Copyright 2017 Jacques Germishuys. | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 204 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 205 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | =cut | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | 1; # End of ZMQ::Raw::Loop::Timer |