1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitSleepViaSelect.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect;
15 use Perl::Critic::Utils qw{ :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
18 our $VERSION = '1.088';
20 #-----------------------------------------------------------------------------
22 Readonly::Scalar my $DESC => q{"select" used to emulate "sleep"};
23 Readonly::Scalar my $EXPL => [168];
24 Readonly::Scalar my $UNDEFS_IN_SLEEP_SELECT => 3;
26 #-----------------------------------------------------------------------------
28 sub supported_parameters { return () }
29 sub default_severity { return $SEVERITY_HIGHEST }
30 sub default_themes { return qw( core pbp bugs ) }
31 sub applies_to { return 'PPI::Token::Word' }
33 #-----------------------------------------------------------------------------
36 my ($self, $elem, undef) = @_;
38 return if ($elem ne 'select');
39 return if ! is_function_call($elem);
42 $UNDEFS_IN_SLEEP_SELECT
43 == grep { $_->[0] eq 'undef' } parse_arg_list($elem)
45 return $self->violation( $DESC, $EXPL, $elem );
54 #-----------------------------------------------------------------------------
60 Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect - Use L<Time::HiRes> instead of something like C<select(undef, undef, undef, .05)>.
64 This Policy is part of the core L<Perl::Critic> distribution.
69 Conway discourages the use of C<select()> for performing non-integer
70 sleeps. Although documented in L<perlfunc>, it's something that
71 generally requires the reader to read C<perldoc -f select> to figure
72 out what it should be doing. Instead, Conway recommends that you use
73 the C<Time::HiRes> module when you want to sleep.
75 select undef, undef, undef, 0.25; # not ok
83 This Policy is not configurable except for the standard options.
92 Graham TerMarsch <graham@howlingfrog.com>
96 Copyright (C) 2005-2007 Graham TerMarsch. All rights reserved.
98 This program is free software; you can redistribute it and/or modify
99 it under the same terms as Perl itself.
105 # cperl-indent-level: 4
107 # indent-tabs-mode: nil
108 # c-indentation-style: bsd
110 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :