Commit | Line | Data |
---|---|---|
34167feb JRT |
1 | ################################################################## |
2 | # $URL$ | |
3 | # $Date$ | |
4 | # $Author$ | |
5 | # $Revision$ | |
6 | ################################################################## | |
7 | ||
59b05e08 JRT |
8 | package Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect; |
9 | ||
10 | use strict; | |
11 | use warnings; | |
12 | use Perl::Critic::Utils; | |
13 | use Perl::Critic::Violation; | |
14 | use base 'Perl::Critic::Policy'; | |
15 | ||
16 | our $VERSION = '0.13'; | |
17 | $VERSION = eval $VERSION; ## no critic; | |
18 | ||
19 | my $desc = q{'select' used to emmulate 'sleep'}; | |
20 | my $expl = [168]; | |
21 | ||
22 | #------------------------------------------------------------------------ | |
23 | ||
24 | sub violates { | |
25 | my ($self, $elem, $doc) = @_; | |
26 | $elem->isa('PPI::Token::Word') && $elem eq 'select' || return; | |
27 | return if is_method_call($elem); | |
28 | return if is_hash_key($elem); | |
29 | ||
30 | if ( 3 == grep {$_->[0] eq 'undef' } parse_arg_list($elem) ){ | |
31 | return Perl::Critic::Violation->new($desc, $expl, $elem->location() ); | |
32 | } | |
33 | return; #ok! | |
34 | } | |
35 | ||
36 | 1; | |
37 | ||
38 | __END__ | |
39 | ||
40 | =pod | |
41 | ||
42 | =head1 NAME | |
43 | ||
44 | Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect | |
45 | ||
46 | =head1 DESCRIPTION | |
47 | ||
48 | Conway discourages the use of C<select()> for performing non-integer | |
49 | sleeps. Although its documented in L<perlfunc>, its something that | |
50 | generally requires the reader to RTFM to figure out what C<select()> | |
51 | is supposed to be doing. Instead, Conway recommends that you use the | |
52 | C<Time::HiRes> module when you want to sleep. | |
53 | ||
54 | select undef, undef, undef, 0.25; # not ok | |
55 | ||
56 | use Time::HiRes; | |
57 | sleep( 0.25 ); # ok | |
58 | ||
59 | =head1 SEE ALSO | |
60 | ||
61 | L<Time::HiRes>. | |
62 | ||
63 | =head1 AUTHOR | |
64 | ||
65 | Graham TerMarsch <graham@howlingfrog.com> | |
66 | ||
67 | =head1 COPYRIGHT | |
68 | ||
69 | Copyright (C) 2005 Graham TerMarsch. All rights reserved. | |
70 | ||
71 | This program is free software; you can redistribute it and/or modify | |
72 | it under the same terms as Perl itself. | |
73 | ||
74 | =cut |