Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / lib / Perl / Critic / Policy / BuiltinFunctions / ProhibitSleepViaSelect.pm
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) $
4 #   $Author: clonezone $
5 # $Revision: 2489 $
6 ##############################################################################
7
8 package Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect;
9
10 use 5.006001;
11 use strict;
12 use warnings;
13 use Readonly;
14
15 use Perl::Critic::Utils qw{ :severities :classification :ppi };
16 use base 'Perl::Critic::Policy';
17
18 our $VERSION = '1.088';
19
20 #-----------------------------------------------------------------------------
21
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;
25
26 #-----------------------------------------------------------------------------
27
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'  }
32
33 #-----------------------------------------------------------------------------
34
35 sub violates {
36     my ($self, $elem, undef) = @_;
37
38     return if ($elem ne 'select');
39     return if ! is_function_call($elem);
40
41     if (
42             $UNDEFS_IN_SLEEP_SELECT
43         ==  grep { $_->[0] eq 'undef' } parse_arg_list($elem)
44     ) {
45         return $self->violation( $DESC, $EXPL, $elem );
46     }
47     return; #ok!
48 }
49
50 1;
51
52 __END__
53
54 #-----------------------------------------------------------------------------
55
56 =pod
57
58 =head1 NAME
59
60 Perl::Critic::Policy::BuiltinFunctions::ProhibitSleepViaSelect - Use L<Time::HiRes> instead of something like C<select(undef, undef, undef, .05)>.
61
62 =head1 AFFILIATION
63
64 This Policy is part of the core L<Perl::Critic> distribution.
65
66
67 =head1 DESCRIPTION
68
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.
74
75   select undef, undef, undef, 0.25;         # not ok
76
77   use Time::HiRes;
78   sleep( 0.25 );                            # ok
79
80
81 =head1 CONFIGURATION
82
83 This Policy is not configurable except for the standard options.
84
85
86 =head1 SEE ALSO
87
88 L<Time::HiRes>.
89
90 =head1 AUTHOR
91
92 Graham TerMarsch <graham@howlingfrog.com>
93
94 =head1 COPYRIGHT
95
96 Copyright (C) 2005-2007 Graham TerMarsch.  All rights reserved.
97
98 This program is free software; you can redistribute it and/or modify
99 it under the same terms as Perl itself.
100
101 =cut
102
103 # Local Variables:
104 #   mode: cperl
105 #   cperl-indent-level: 4
106 #   fill-column: 78
107 #   indent-tabs-mode: nil
108 #   c-indentation-style: bsd
109 # End:
110 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :