line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perinci::Sub::Property::timeout; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4043129
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
987
|
use Perinci::Sub::PropertyUtil qw(declare_property); |
|
1
|
|
|
|
|
1258
|
|
|
1
|
|
|
|
|
261
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
declare_property( |
12
|
|
|
|
|
|
|
name => 'timeout', |
13
|
|
|
|
|
|
|
type => 'function', |
14
|
|
|
|
|
|
|
schema => ['int*' => {min=>0}], |
15
|
|
|
|
|
|
|
wrapper => { |
16
|
|
|
|
|
|
|
meta => { |
17
|
|
|
|
|
|
|
v => 2, |
18
|
|
|
|
|
|
|
# highest, we need to disable alarm right after call |
19
|
|
|
|
|
|
|
prio => 1, |
20
|
|
|
|
|
|
|
convert => 1, |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
handler => sub { |
23
|
4
|
|
|
4
|
|
4028808
|
my ($self, %args) = @_; |
24
|
4
|
|
33
|
|
|
26
|
my $v = int($args{new} // $args{value} // 0); |
|
|
|
50
|
|
|
|
|
25
|
4
|
|
|
|
|
11
|
my $meta = $args{meta}; |
26
|
|
|
|
|
|
|
|
27
|
4
|
50
|
|
|
|
75
|
return unless $v > 0; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
14
|
$self->select_section('before_call_right_before_call'); |
30
|
4
|
|
|
|
|
59
|
$self->push_lines( |
31
|
|
|
|
|
|
|
'local $SIG{ALRM} = sub { die "Timed out\n" };', |
32
|
|
|
|
|
|
|
"alarm($v);"); |
33
|
|
|
|
|
|
|
|
34
|
4
|
|
|
|
|
133
|
$self->select_section('after_call_right_after_call'); |
35
|
4
|
|
|
|
|
57
|
$self->push_lines('alarm(0);'); |
36
|
|
|
|
|
|
|
|
37
|
4
|
|
|
|
|
117
|
$self->select_section('after_eval'); |
38
|
4
|
|
|
|
|
55
|
$self->_errif(504, "\"Timed out ($v sec(s))\"", |
39
|
|
|
|
|
|
|
'$_w_eval_err =~ /\ATimed out\b/'); |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
# ABSTRACT: Specify function execution time limit |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |