File Coverage

blib/lib/Perl/Critic/Policy/Compatibility/ProhibitThreeArgumentOpen.pm
Criterion Covered Total %
statement 33 34 97.0
branch 7 8 87.5
condition 3 3 100.0
subroutine 11 12 91.6
pod 4 5 80.0
total 58 62 93.5


line stmt bran cond sub pod time code
1             # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic-Compatibility/lib/Perl/Critic/Policy/Compatibility/ProhibitThreeArgumentOpen.pm $
2             # $Date: 2008-06-07 22:26:28 -0500 (Sat, 07 Jun 2008) $
3             # $Author: clonezone $
4             # $Revision: 2425 $
5              
6             package Perl::Critic::Policy::Compatibility::ProhibitThreeArgumentOpen;
7              
8 1     1   1217262 use 5.006;
  1         3  
  1         33  
9              
10 1     1   5 use strict;
  1         1  
  1         27  
11 1     1   4 use warnings;
  1         6  
  1         45  
12              
13             our $VERSION = '1.001';
14              
15 1     1   5 use Readonly ();
  1         2  
  1         15  
16 1     1   4 use version ();
  1         1  
  1         16  
17              
18 1     1   6 use Perl::Critic::Utils qw< :severities is_function_call parse_arg_list >;
  1         1  
  1         89  
19              
20 1     1   156 use base 'Perl::Critic::Policy';
  1         1  
  1         951  
21              
22             Readonly::Scalar my $DESCRIPTION => 'Three-argument form of open used';
23             Readonly::Scalar my $EXPLANATION => 'Three-argument open is not available until perl 5.6.';
24              
25             Readonly::Scalar my $MINIMUM_VERSION => version->new(5.006);
26              
27 5     5 0 32570 sub supported_parameters { return (); }
28 4     4 1 46 sub default_severity { return $SEVERITY_HIGHEST; }
29 0     0 1 0 sub default_themes { return qw( compatibility ); }
30 5     5 1 48446 sub applies_to { return 'PPI::Token::Word' }
31              
32             sub violates {
33 30     30 1 7197 my ( $self, $element, $document ) = @_;
34              
35 30 100       82 return if $element->content() ne 'open';
36 9 50       87 return if not is_function_call($element);
37              
38 9         2531 my $version = $document->highest_explicit_perl_version();
39 9 100 100     3172 return if $version && $version >= $MINIMUM_VERSION;
40              
41 5         26 my @arguments = parse_arg_list($element);
42              
43 5 100       1566 if ( scalar @arguments > 2 ) {
44 4         26 return $self->violation( $DESCRIPTION, $EXPLANATION, $element );
45             }
46              
47 1         4 return;
48             } # end violates()
49              
50             1;
51              
52             __END__
53              
54             =pod
55              
56             =head1 NAME
57              
58             Perl::Critic::Policy::Compatibility::ProhibitThreeArgumentOpen - Don't allow three-argument open unless the code uses a version of perl that supports it.
59              
60              
61             =head1 AFFILIATION
62              
63             This policy is part of L<Perl::Critic::Compatibility>.
64              
65              
66             =head1 VERSION
67              
68             This document describes
69             Perl::Critic::Policy::Compatibility::ProhibitThreeArgumentOpen version
70             1.001.
71              
72              
73             =head1 SYNOPSIS
74              
75             Don't allow three-argument C<open> unless the module declares a
76             dependency upon perl 5.6 or higher.
77              
78              
79             =head1 DESCRIPTION
80              
81             Perls prior to 5.6 don't support the three-argument form of C<open>.
82             If you want your code to remain compatible with those versions of
83             perl, you can't use it.
84              
85             If your code explicitly declares a requirement on a version of perl
86             greater than or equal to 5.6, then three-argument C<open> is fine.
87              
88             open FILE, '<', 'blah'; # not ok
89              
90             use 5.006;
91             open FILE, '<', 'blah'; # ok
92              
93             require 5.8.8;
94             open FILE, '<', 'blah'; # ok
95              
96              
97             =head1 INTERFACE
98              
99             Standard for a L<Perl::Critic::Policy>.
100              
101              
102             =head1 DIAGNOSTICS
103              
104             None.
105              
106              
107             =head1 CONFIGURATION AND ENVIRONMENT
108              
109             This policy has no configuration options beyond the standard ones.
110              
111              
112             =head1 DEPENDENCIES
113              
114             L<Perl::Critic>
115              
116              
117             =head1 INCOMPATIBILITIES
118              
119             This policy directly contradicts
120             L<Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen>. If you don't
121             declare perl version requirements, then you cannot have both of these
122             policies enabled at the same time (unless you like getting
123             violations).
124              
125              
126             =head1 BUGS AND LIMITATIONS
127              
128             No bugs have been reported.
129              
130             Please report any bugs or feature requests to
131             C<bug-perl-critic-compatible@rt.cpan.org>, or through the web
132             interface at L<http://rt.cpan.org>.
133              
134              
135             =head1 ACKNOWLEDGMENTS
136              
137             Adam Kennedy for inspiring this. Nay, demanding it.
138              
139              
140             =head1 AUTHOR
141              
142             Elliot Shank C<< <perl@galumph.com> >>
143              
144              
145             =head1 LICENSE AND COPYRIGHT
146              
147             Copyright (c)2008, Elliot Shank C<< <perl@galumph.com> >>. All rights
148             reserved.
149              
150             This module is free software; you can redistribute it and/or modify it
151             under the same terms as Perl itself. See L<perlartistic>.
152              
153              
154             =head1 DISCLAIMER OF WARRANTY
155              
156             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
157             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
158             WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
159             PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
160             EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
161             IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
162             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
163             SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
164             THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
165              
166             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
167             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
168             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE
169             TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
170             CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
171             SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
172             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
173             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
174             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
175             DAMAGES.
176              
177              
178             =cut
179              
180             # setup vim: set filetype=perl tabstop=4 softtabstop=4 expandtab :
181             # setup vim: set shiftwidth=4 shiftround textwidth=78 nowrap autoindent :
182             # setup vim: set foldmethod=indent foldlevel=0 :