line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26617
|
use 5.010001; |
|
40
|
|
|
|
|
213
|
|
4
|
40
|
|
|
40
|
|
283
|
use strict; |
|
40
|
|
|
|
|
122
|
|
|
40
|
|
|
|
|
866
|
|
5
|
40
|
|
|
40
|
|
239
|
use warnings; |
|
40
|
|
|
|
|
131
|
|
|
40
|
|
|
|
|
1223
|
|
6
|
40
|
|
|
40
|
|
246
|
use Readonly; |
|
40
|
|
|
|
|
181
|
|
|
40
|
|
|
|
|
2322
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
368
|
use Perl::Critic::Utils qw{ :severities :classification :ppi }; |
|
40
|
|
|
|
|
137
|
|
|
40
|
|
|
|
|
2190
|
|
9
|
40
|
|
|
40
|
|
15692
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
171
|
|
|
40
|
|
|
|
|
317
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.146'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{"select" used to emulate "sleep"}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [168]; |
17
|
|
|
|
|
|
|
Readonly::Scalar my $SELECT_ARGUMENT_COUNT => 4; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
97
|
|
|
97
|
0
|
1680
|
sub supported_parameters { return () } |
22
|
77
|
|
|
77
|
1
|
373
|
sub default_severity { return $SEVERITY_HIGHEST } |
23
|
92
|
|
|
92
|
1
|
402
|
sub default_themes { return qw( core pbp bugs ) } |
24
|
44
|
|
|
44
|
1
|
144
|
sub applies_to { return 'PPI::Token::Word' } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub violates { |
29
|
392
|
|
|
392
|
1
|
771
|
my ($self, $elem, undef) = @_; |
30
|
|
|
|
|
|
|
|
31
|
392
|
100
|
|
|
|
793
|
return if $elem->content() ne 'select'; |
32
|
8
|
100
|
|
|
|
54
|
return if ! is_function_call($elem); |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
25
|
my @arguments = parse_arg_list($elem); |
35
|
7
|
50
|
|
|
|
23
|
return if $SELECT_ARGUMENT_COUNT != @arguments; |
36
|
|
|
|
|
|
|
|
37
|
7
|
|
|
|
|
30
|
foreach my $argument ( @arguments[0..2] ) { |
38
|
16
|
100
|
|
|
|
150
|
return if $argument->[0] ne 'undef'; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
3
|
50
|
|
|
|
45
|
if ( $arguments[-1]->[0] ne 'undef' ) { |
42
|
3
|
|
|
|
|
55
|
return $self->violation( $DESC, $EXPL, $elem ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return; #ok! |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=pod |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=for stopwords perlfunc |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect - Use L<Time::HiRes|Time::HiRes> instead of something like C<select(undef, undef, undef, .05)>. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 AFFILIATION |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
66
|
|
|
|
|
|
|
distribution. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Conway discourages the use of C<select()> for performing non-integer |
72
|
|
|
|
|
|
|
sleeps. Although documented in L<perlfunc|perlfunc>, it's something |
73
|
|
|
|
|
|
|
that generally requires the reader to read C<perldoc -f select> to |
74
|
|
|
|
|
|
|
figure out what it should be doing. Instead, Conway recommends that |
75
|
|
|
|
|
|
|
you use the C<Time::HiRes> module when you want to sleep. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
select undef, undef, undef, 0.25; # not ok |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use Time::HiRes; |
80
|
|
|
|
|
|
|
sleep( 0.25 ); # ok |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CONFIGURATION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<Time::HiRes|Time::HiRes>. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Graham TerMarsch <graham@howlingfrog.com> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Graham TerMarsch. All rights reserved. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
103
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# Local Variables: |
108
|
|
|
|
|
|
|
# mode: cperl |
109
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
110
|
|
|
|
|
|
|
# fill-column: 78 |
111
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
112
|
|
|
|
|
|
|
# c-indentation-style: bsd |
113
|
|
|
|
|
|
|
# End: |
114
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |