Login
Added svn keywords.
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / BuiltinFunctions / ProhibitSleepViaSelect.pm
CommitLineData
34167feb
JRT
1##################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6##################################################################
7
59b05e08
JRT
8package Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect;
9
10use strict;
11use warnings;
12use Perl::Critic::Utils;
13use Perl::Critic::Violation;
14use base 'Perl::Critic::Policy';
15
16our $VERSION = '0.13';
17$VERSION = eval $VERSION; ## no critic;
18
19my $desc = q{'select' used to emmulate 'sleep'};
20my $expl = [168];
21
22#------------------------------------------------------------------------
23
24sub 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
361;
37
38__END__
39
40=pod
41
42=head1 NAME
43
44Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect
45
46=head1 DESCRIPTION
47
48Conway discourages the use of C<select()> for performing non-integer
49sleeps. Although its documented in L<perlfunc>, its something that
50generally requires the reader to RTFM to figure out what C<select()>
51is supposed to be doing. Instead, Conway recommends that you use the
52C<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
61L<Time::HiRes>.
62
63=head1 AUTHOR
64
65Graham TerMarsch <graham@howlingfrog.com>
66
67=head1 COPYRIGHT
68
69Copyright (C) 2005 Graham TerMarsch. All rights reserved.
70
71This program is free software; you can redistribute it and/or modify
72it under the same terms as Perl itself.
73
74=cut