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