File Coverage

blib/lib/Perl/Critic/Policy/Tics/ProhibitUseBase.pm
Criterion Covered Total %
statement 17 18 94.4
branch 2 2 100.0
condition n/a
subroutine 7 8 87.5
pod 4 4 100.0
total 30 32 93.7


line stmt bran cond sub pod time code
1 5     5   865315 use strict;
  5         48  
  5         149  
2 5     5   24 use warnings;
  5         9  
  5         312  
3             package Perl::Critic::Policy::Tics::ProhibitUseBase 0.010;
4             # ABSTRACT: do not use base.pm
5              
6             #pod =head1 DESCRIPTION
7             #pod
8             #pod use base qw(Baseclass);
9             #pod
10             #pod You've seen that a hundred times, right? That doesn't mean that it's a good
11             #pod idea. It screws with C<$VERSION>, it alters (for the worse) the exceptions
12             #pod reported by failure-to-require, it doesn't let you call the base class's
13             #pod C<import> method, it pushes to C<@INC> rather than replacing it, and it uses
14             #pod and documents interactions with L<fields|fields>, which can lead one to believe
15             #pod that fields are even remotely relevant to modern (or any!) development of Perl
16             #pod classes.
17             #pod
18             #pod There are a lot of ways around using C<base>. Pick one.
19             #pod
20             #pod =head1 WARNING
21             #pod
22             #pod This policy caused a bit of controversy, largely in this form:
23             #pod
24             #pod These behaviors are either correct or can be worked around, and using base.pm
25             #pod protects you from the problem of remembering to load prereqs and from
26             #pod setting @INC at runtime.
27             #pod
28             #pod These are true statements. My chosen workaround for all these problems is to
29             #pod I<not use base.pm>. That doesn't mean it's a good idea for you, or anyone
30             #pod else. Heck, it doesn't mean it's a good idea for me, either. It's just my
31             #pod preference. As with all Perl::Critic policies, you should decide whether it's
32             #pod right for you.
33             #pod
34             #pod =cut
35              
36 5     5   35 use Perl::Critic::Utils;
  5         11  
  5         100  
37 5     5   4274 use parent qw(Perl::Critic::Policy);
  5         21  
  5         55  
38              
39             my $DESCRIPTION = q{Use of "base" pragma};
40             my $EXPLANATION = q{Don't use base, set @INC or use a base.pm alternative.};
41              
42 2     2 1 26 sub default_severity { $SEVERITY_LOW }
43 0     0 1 0 sub default_themes { qw(tics) }
44 3     3 1 38442 sub applies_to { 'PPI::Statement::Include' }
45              
46             sub violates {
47 3     3 1 73 my ($self, $elem, $doc) = @_;
48              
49 3 100       14 return unless $elem->module eq 'base';
50              
51             # Must be a violation...
52 2         68 return $self->violation($DESCRIPTION, $EXPLANATION, $elem);
53             }
54              
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =encoding UTF-8
62              
63             =head1 NAME
64              
65             Perl::Critic::Policy::Tics::ProhibitUseBase - do not use base.pm
66              
67             =head1 VERSION
68              
69             version 0.010
70              
71             =head1 DESCRIPTION
72              
73             use base qw(Baseclass);
74              
75             You've seen that a hundred times, right? That doesn't mean that it's a good
76             idea. It screws with C<$VERSION>, it alters (for the worse) the exceptions
77             reported by failure-to-require, it doesn't let you call the base class's
78             C<import> method, it pushes to C<@INC> rather than replacing it, and it uses
79             and documents interactions with L<fields|fields>, which can lead one to believe
80             that fields are even remotely relevant to modern (or any!) development of Perl
81             classes.
82              
83             There are a lot of ways around using C<base>. Pick one.
84              
85             =head1 PERL VERSION
86              
87             This library should run on perls released even a long time ago. It should work
88             on any version of perl released in the last five years.
89              
90             Although it may work on older versions of perl, no guarantee is made that the
91             minimum required version will not be increased. The version may be increased
92             for any reason, and there is no promise that patches will be accepted to lower
93             the minimum required perl.
94              
95             =head1 WARNING
96              
97             This policy caused a bit of controversy, largely in this form:
98              
99             These behaviors are either correct or can be worked around, and using base.pm
100             protects you from the problem of remembering to load prereqs and from
101             setting @INC at runtime.
102              
103             These are true statements. My chosen workaround for all these problems is to
104             I<not use base.pm>. That doesn't mean it's a good idea for you, or anyone
105             else. Heck, it doesn't mean it's a good idea for me, either. It's just my
106             preference. As with all Perl::Critic policies, you should decide whether it's
107             right for you.
108              
109             =head1 AUTHOR
110              
111             Ricardo SIGNES <cpan@semiotic.systems>
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             This software is copyright (c) 2007 by Ricardo SIGNES.
116              
117             This is free software; you can redistribute it and/or modify it under
118             the same terms as the Perl 5 programming language system itself.
119              
120             =cut