File Coverage

blib/lib/Perl/Critic/Policy/Freenode/DiscouragedModules.pm
Criterion Covered Total %
statement 22 23 95.6
branch 2 2 100.0
condition 3 6 50.0
subroutine 9 10 90.0
pod 4 5 80.0
total 40 46 86.9


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Freenode::DiscouragedModules;
2              
3 1     1   750 use strict;
  1         3  
  1         33  
4 1     1   5 use warnings;
  1         2  
  1         34  
5              
6 1     1   5 use Perl::Critic::Utils qw(:severities :classification :ppi);
  1         3  
  1         50  
7 1     1   328 use parent 'Perl::Critic::Policy';
  1         2  
  1         4  
8              
9             our $VERSION = '0.033';
10              
11 2     2 0 12500 sub supported_parameters { () }
12 15     15 1 140 sub default_severity { $SEVERITY_HIGH }
13 0     0 1 0 sub default_themes { 'freenode' }
14 2     2 1 57865 sub applies_to { 'PPI::Statement::Include' }
15              
16             my %modules = (
17             'AnyEvent' => 'AnyEvent\'s author refuses to use public bugtracking and actively breaks interoperability. POE, IO::Async, and Mojo::IOLoop are widely used and interoperable async event loops.',
18             'Any::Moose' => 'Any::Moose is deprecated. Use Moo instead.',
19             'Class::DBI' => 'Class::DBI is an ancient database ORM abstraction layer which is buggy and abandoned. See DBIx::Class for a more modern DBI-based ORM, or Mad::Mapper for a Mojolicious-style ORM.',
20             'CGI' => 'CGI.pm is an ancient module for communicating via the CGI protocol, with tons of bad practices and cruft. Use a modern framework such as those based on Plack (Web::Simple, Dancer2, Catalyst) or Mojolicious, they can still be served via CGI if you choose.',
21             'Coro' => 'Coro abuses Perl internals in an unsupported way. Consider Future and Future::AsyncAwait in combination with event loops for similar semantics.',
22             'Error' => 'Error.pm is overly magical and discouraged by its maintainers. Try Throwable for exception classes in Moo/Moose, or Exception::Class otherwise. Try::Tiny or Syntax::Keyword::Try are recommended for the try/catch syntax.',
23             'File::Slurp' => 'File::Slurp gets file encodings all wrong, line endings on win32 are messed up, and it was written before layers were properly added. Use File::Slurper, Path::Tiny, Data::Munge, or Mojo::File.',
24             'FindBin' => 'FindBin depends on the sometimes vague definition of "initial script" and can\'t be updated to fix bugs in old Perls. Use Path::This or lib::relative to work with the absolute path of the current source file instead.',
25             'HTML::Template' => 'HTML::Template is an old and buggy module, try Template Toolkit, Mojo::Template, or Text::Xslate instead, or HTML::Template::Pro if you must use the same syntax.',
26             'IO::Socket::INET6' => 'IO::Socket::INET6 is an old attempt at an IPv6 compatible version of IO::Socket::INET, but has numerous issues and is discouraged by the maintainer in favor of IO::Socket::IP, which transparently creates IPv4 and IPv6 sockets.',
27             'JSON::Any' => 'JSON::Any is deprecated. Use JSON::MaybeXS instead.',
28             'JSON::XS' => 'JSON::XS\'s author refuses to use public bugtracking and actively breaks interoperability. Cpanel::JSON::XS is a fork with several bugfixes and a more collaborative maintainer. See also JSON::MaybeXS.',
29             'Net::IRC' => 'Net::IRC is an ancient module implementing the IRC protocol. Use a modern event-loop-based module instead. Choices are POE::Component::IRC (and Bot::BasicBot based on that), Net::Async::IRC, and Mojo::IRC.',
30             'Switch' => 'Switch.pm is a buggy and outdated source filter which can cause any number of strange errors, in addition to the problems with smart-matching shared by its replacement, the \'switch\' feature (given/when). Try Switch::Plain instead.',
31             'XML::Simple' => 'XML::Simple tries to coerce complex XML documents into perl data structures. This leads to overcomplicated structures and unexpected behavior. Use a proper DOM parser instead like XML::LibXML, XML::TreeBuilder, XML::Twig, or Mojo::DOM.',
32             );
33              
34             sub _violation {
35 15     15   313 my ($self, $module, $elem) = @_;
36 15         44 my $desc = "Used module $module";
37 15   33     40 my $expl = $modules{$module} // "Module $module is discouraged.";
38 15         47 return $self->violation($desc, $expl, $elem);
39             }
40              
41             sub violates {
42 50     50 1 4170 my ($self, $elem) = @_;
43 50 100 66     117 return () unless defined $elem->module and exists $modules{$elem->module};
44 15         710 return $self->_violation($elem->module, $elem);
45             }
46              
47             1;
48              
49             =head1 NAME
50              
51             Perl::Critic::Policy::Freenode::DiscouragedModules - Various modules
52             discouraged from use
53              
54             =head1 DESCRIPTION
55              
56             Various modules are discouraged by the denizens of #perl on Freenode IRC, for
57             various reasons which may include: buggy behavior, cruft, performance problems,
58             maintainer issues, or simply better modern replacements. This is a high
59             severity complement to
60             L<Perl::Critic::Policy::Freenode::PreferredAlternatives>.
61              
62             =head1 MODULES
63              
64             =head2 AnyEvent
65              
66             L<AnyEvent>'s author refuses to use public bugtracking and actively breaks
67             interoperability. L<POE>, L<IO::Async>, and L<Mojo::IOLoop> are widely used and
68             interoperable async event loops.
69              
70             =head2 Any::Moose
71              
72             L<Any::Moose> is deprecated. Use L<Moo> instead.
73              
74             =head2 Class::DBI
75              
76             L<Class::DBI> is an ancient database L<ORM|https://en.wikipedia.org/wiki/Object-relational_mapping>
77             abstraction layer which is buggy and abandoned. See L<DBIx::Class> for a more
78             modern L<DBI>-based ORM, or L<Mad::Mapper> for a L<Mojolicious>-style ORM.
79              
80             =head2 CGI
81              
82             L<CGI>.pm is an ancient module for communicating via the CGI protocol, with
83             tons of bad practices and cruft. Use a modern framework such as those based on
84             L<Plack> (L<Web::Simple>, L<Dancer2>, L<Catalyst>) or L<Mojolicious>, they can
85             still be served via CGI if you choose.
86              
87             =head2 Coro
88              
89             L<Coro> abuses Perl internals in an unsupported way. Consider L<Future> and
90             L<Future::AsyncAwait> in combination with event loops for similar semantics.
91              
92             =head2 Error
93              
94             L<Error>.pm is overly magical and discouraged by its maintainers. Try
95             L<Throwable> for exception classes in L<Moo>/L<Moose>, or L<Exception::Class>
96             otherwise. L<Try::Tiny> or L<Syntax::Keyword::Try> are recommended for the
97             C<try>/C<catch> syntax.
98              
99             =head2 FindBin
100              
101             L<FindBin> is often used to retrieve the absolute path to the directory
102             containing the initially executed script, a mechanism which is not always
103             logically clear. Additionally, it has serious bugs on old Perls and can't be
104             updated from CPAN to fix them. The L<Path::This> module provides similar
105             variables and constants based on the absolute path to the current source file.
106             The L<lib::relative> module resolves passed relative paths to the current
107             source file for the common case of adding local module include directories.
108             Each of these documents examples of achieving the same behavior with core
109             modules.
110              
111             =head2 File::Slurp
112              
113             L<File::Slurp> gets file encodings all wrong, line endings on win32 are messed
114             up, and it was written before layers were properly added. Use L<File::Slurper>,
115             L<Path::Tiny/"slurp">, L<Data::Munge/"slurp">, or L<Mojo::File/"slurp">.
116              
117             =head2 HTML::Template
118              
119             L<HTML::Template> is an old and buggy module, try L<Template::Toolkit>,
120             L<Mojo::Template>, or L<Text::Xslate> instead, or L<HTML::Template::Pro> if you
121             must use the same syntax.
122              
123             =head2 IO::Socket::INET6
124              
125             L<IO::Socket::INET6> is an old attempt at an IPv6 compatible version of
126             L<IO::Socket::INET>, but has numerous issues and is discouraged by the
127             maintainer in favor of L<IO::Socket::IP>, which transparently creates IPv4 and
128             IPv6 sockets.
129              
130             =head2 JSON::Any
131              
132             L<JSON::Any> is deprecated. Use L<JSON::MaybeXS> instead.
133              
134             =head2 JSON::XS
135              
136             L<JSON::XS>'s author refuses to use public bugtracking and actively breaks
137             interoperability. L<Cpanel::JSON::XS> is a fork with several bugfixes and a
138             more collaborative maintainer. See also L<JSON::MaybeXS>.
139              
140             =head2 Net::IRC
141              
142             L<Net::IRC> is an ancient module implementing the IRC protocol. Use a modern
143             event-loop-based module instead. Choices are L<POE::Component::IRC> (used for
144             L<Bot::BasicBot>), L<Net::Async::IRC>, and L<Mojo::IRC>.
145              
146             =head2 Switch
147              
148             L<Switch>.pm is a buggy and outdated source filter which can cause any number
149             of strange errors, in addition to the problems with smart-matching shared by
150             its replacement, L<feature/"The 'switch' feature"> (C<given>/C<when>). Try
151             L<Switch::Plain> instead.
152              
153             =head2 XML::Simple
154              
155             L<XML::Simple> tries to coerce complex XML documents into perl data structures.
156             This leads to overcomplicated structures and unexpected behavior. Use a proper
157             DOM parser instead like L<XML::LibXML>, L<XML::TreeBuilder>, L<XML::Twig>, or
158             L<Mojo::DOM>.
159              
160             =head1 AFFILIATION
161              
162             This policy is part of L<Perl::Critic::Freenode>.
163              
164             =head1 CONFIGURATION
165              
166             This policy is not configurable except for the standard options.
167              
168             =head1 AUTHOR
169              
170             Dan Book, C<dbook@cpan.org>
171              
172             =head1 COPYRIGHT AND LICENSE
173              
174             Copyright 2015, Dan Book.
175              
176             This library is free software; you may redistribute it and/or modify it under
177             the terms of the Artistic License version 2.0.
178              
179             =head1 SEE ALSO
180              
181             L<Perl::Critic>