line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! /bin/false |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Devel-throttle. |
4
|
|
|
|
|
|
|
# Copyright (C) 2009 Guido Flohr , |
5
|
|
|
|
|
|
|
# all rights reserved. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
8
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Devel::throttle; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1159
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use vars qw ($VERSION @args); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
403
|
|
15
|
|
|
|
|
|
|
$VERSION = '0.01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
1
|
|
|
1
|
|
9
|
my ($self, $throttle, @code) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
2
|
$DB::throttle = $throttle; |
21
|
|
|
|
|
|
|
|
22
|
1
|
50
|
|
|
|
5
|
if (@code) { |
23
|
0
|
|
|
|
|
0
|
my $code = shift @code; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
0
|
|
|
0
|
if (ref $code && 'CODE' eq ref $code) { |
26
|
0
|
|
|
|
|
0
|
$DB::throttlefunc = $code; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
0
|
0
|
|
|
0
|
if (ref $code && 'CODE' eq ref $code) { |
30
|
0
|
|
|
|
|
0
|
@args = @code; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
0
|
@args = (); |
33
|
0
|
0
|
|
0
|
|
0
|
$DB::throttlefunc = sub { eval $code; warn $@ if $@ }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} else { |
36
|
1
|
|
|
|
|
1772
|
@args = (); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub throttlefunc { |
41
|
0
|
|
0
|
0
|
1
|
|
my $timeout = shift || 0; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$timeout *= 1; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
return unless $timeout > 0; |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
select undef, undef, undef, $timeout |
48
|
|
|
|
|
|
|
if $timeout; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
package DB; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$DB::throttlefunc = \&Devel::throttle::throttlefunc; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub DB { |
56
|
0
|
0
|
|
0
|
0
|
|
my @args = @Devel::throttle::args ? |
57
|
|
|
|
|
|
|
@Devel::throttle::args : $DB::throttle; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
$DB::throttlefunc->(@args) |
60
|
|
|
|
|
|
|
if $DB::throttlefunc; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |