File Coverage

blib/lib/Perl/Critic/Policy/ErrorHandling/RequireUseOfExceptions.pm
Criterion Covered Total %
statement 26 26 100.0
branch 4 4 100.0
condition n/a
subroutine 11 11 100.0
pod 4 5 80.0
total 45 46 97.8


line stmt bran cond sub pod time code
1             ##############################################################################
2             # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic-More/lib/Perl/Critic/Policy/ErrorHandling/RequireUseOfExceptions.pm $
3             # $Date: 2013-10-29 09:39:11 -0700 (Tue, 29 Oct 2013) $
4             # $Author: thaljef $
5             # $Revision: 4222 $
6             ##############################################################################
7              
8             package Perl::Critic::Policy::ErrorHandling::RequireUseOfExceptions;
9              
10 6     6   5678 use 5.006001;
  6         20  
  6         241  
11              
12 6     6   35 use strict;
  6         9  
  6         172  
13 6     6   29 use warnings;
  6         10  
  6         210  
14              
15 6     6   29 use Readonly;
  6         13  
  6         300  
16              
17 6     6   34 use Perl::Critic::Utils qw{ :severities :classification :data_conversion };
  6         10  
  6         546  
18 6     6   2706 use base 'Perl::Critic::Policy';
  6         11  
  6         1593  
19              
20             our $VERSION = '1.003';
21              
22             #-----------------------------------------------------------------------------
23              
24 10     10 1 329 sub default_severity { return $SEVERITY_HIGH }
25 1     1 1 88 sub default_themes { return qw< more maintenance > }
26 2     2 1 42817 sub applies_to { return 'PPI::Token::Word' }
27 3     3 0 25052 sub supported_parameters { return () }
28              
29             #-----------------------------------------------------------------------------
30              
31             Readonly::Hash my %FATAL_FUNCTIONS => hashify(qw< die croak confess >);
32              
33             sub violates {
34 33     33 1 2681 my ( $self, $elem, undef ) = @_;
35              
36 33 100       80 return if not exists $FATAL_FUNCTIONS{$elem};
37              
38 18 100       215 return if not is_function_call($elem);
39              
40 9         2036 return $self->violation(
41             "Found use of $elem. Use an exception instead.",
42             'Exception objects should be used instead of the standard Perl error mechanism.',
43             $elem,
44             );
45             }
46              
47             1;
48              
49             __END__
50              
51             #-----------------------------------------------------------------------------
52              
53             =pod
54              
55             =head1 NAME
56              
57             Perl::Critic::Policy::ErrorHandling::RequireUseOfExceptions - Use exceptions instead of C<die>, C<croak>, or C<confess>.
58              
59             =head1 AFFILIATION
60              
61             This policy is part of L<Perl::Critic::More|Perl::Critic::More>, a bleeding
62             edge supplement to L<Perl::Critic|Perl::Critic>.
63              
64             =head1 DESCRIPTION
65              
66             If the decision is made that a system should use exceptions, then there should
67             be no use of C<die>, C<croak>, or C<confess>.
68              
69             =head1 AUTHOR
70              
71             Elliot Shank C<< <perl@galumph.org> >>
72              
73             =head1 COPYRIGHT
74              
75             Copyright (c) 2007-2008 Elliot Shank. All rights reserved.
76              
77             This program is free software; you can redistribute it and/or modify
78             it under the same terms as Perl itself. The full text of this license
79             can be found in the LICENSE file included with this module.
80              
81             =cut
82              
83             # Local Variables:
84             # mode: cperl
85             # cperl-indent-level: 4
86             # fill-column: 78
87             # indent-tabs-mode: nil
88             # c-indentation-style: bsd
89             # End:
90             # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :