File Coverage

blib/lib/Perl/Critic/Policy/Freenode/Threads.pm
Criterion Covered Total %
statement 23 25 92.0
branch 1 2 50.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 38 43 88.3


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Freenode::Threads;
2              
3 1     1   273243 use strict;
  1         10  
  1         31  
4 1     1   6 use warnings;
  1         2  
  1         31  
5              
6 1     1   6 use Perl::Critic::Utils qw(:severities :classification :ppi);
  1         1  
  1         65  
7 1     1   421 use parent 'Perl::Critic::Policy';
  1         3  
  1         8  
8              
9             our $VERSION = '0.030';
10              
11 1     1   17357 use constant DESC => 'Using interpreter threads';
  1         3  
  1         78  
12 1     1   7 use constant EXPL => 'Interpreter threads are discouraged, they are not lightweight and fast as other threads may be. Try an event loop, forks.pm, or Parallel::Prefork.';
  1         2  
  1         142  
13              
14 2     2 0 5552 sub supported_parameters { () }
15 1     1 1 49 sub default_severity { $SEVERITY_MEDIUM }
16 0     0 1 0 sub default_themes { 'freenode' }
17 2     2 1 8229 sub applies_to { 'PPI::Statement::Include' }
18              
19             sub violates {
20 1     1 1 20 my ($self, $elem) = @_;
21 1 50       4 return $self->violation(DESC, EXPL, $elem) if $elem->pragma eq 'threads';
22 0           return ();
23             }
24              
25             1;
26              
27             =head1 NAME
28              
29             Perl::Critic::Policy::Freenode::Threads - Interpreter-based threads are
30             officially discouraged
31              
32             =head1 DESCRIPTION
33              
34             Perl interpreter L<threads> are officially discouraged. They were created to
35             emulate C<fork()> in Windows environments, and are not fast or lightweight as
36             one may expect. Non-blocking code or I/O can be easily parallelized by using an
37             event loop such as L<POE>, L<IO::Async>, or L<Mojo::IOLoop>. Blocking code is
38             usually better parallelized by forking, which on Unix-like systems is fast and
39             efficient. Modules such as L<forks> and L<Parallel::Prefork> can make forking
40             easier to work with, as well as forking modules for event loops such as
41             L<POE::Wheel::Run>, L<IO::Async::Process>, or L<Mojo::IOLoop/"subprocess">.
42              
43             =head1 AFFILIATION
44              
45             This policy is part of L<Perl::Critic::Freenode>.
46              
47             =head1 CONFIGURATION
48              
49             This policy is not configurable except for the standard options.
50              
51             =head1 AUTHOR
52              
53             Dan Book, C<dbook@cpan.org>
54              
55             =head1 COPYRIGHT AND LICENSE
56              
57             Copyright 2015, Dan Book.
58              
59             This library is free software; you may redistribute it and/or modify it under
60             the terms of the Artistic License version 2.0.
61              
62             =head1 SEE ALSO
63              
64             L<Perl::Critic>