1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/CodeLayout/RequireConsistentNewlines.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines;
15 use Perl::Critic::Utils qw{ :severities };
16 use PPI::Token::Whitespace;
17 use English qw(-no_match_vars);
18 use base 'Perl::Critic::Policy';
20 our $VERSION = '1.088';
22 Readonly::Scalar my $LINE_END => qr/\015{1,2}\012|\012|\015/mxs;
24 #-----------------------------------------------------------------------------
26 Readonly::Scalar my $DESC => q{Use the same newline through the source};
27 Readonly::Scalar my $EXPL => q{Change your newlines to be the same throughout};
29 #-----------------------------------------------------------------------------
31 sub supported_parameters { return () }
32 sub default_severity { return $SEVERITY_HIGH }
33 sub default_themes { return qw( core bugs ) }
34 sub applies_to { return 'PPI::Document' }
36 #-----------------------------------------------------------------------------
39 my ( $self, undef, $doc ) = @_;
41 my $filename = $doc->filename();
45 return if !open $fh, '<', $filename;
50 my $newline; # undef until we find the first one
53 while ( $source =~ m/\G([^\012\015]*)($LINE_END)/cgmxs ) {
56 my $col = length $code;
58 if ( $nl ne $newline ) {
59 my $token = PPI::Token::Whitespace->new( $nl );
60 $token->{_location} = [$line, $col, $col];
61 push @v, $self->violation( $DESC, $EXPL, $token );
70 #-----------------------------------------------------------------------------
80 Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines - Use the same newline through the source.
85 This Policy is not configurable except for the standard options.
90 This policy works outside of PPI because PPI automatically normalizes
91 source code to local newline conventions. So, this will only work if
92 we know the filename of the source code.
96 This Policy is part of the core L<Perl::Critic> distribution.
101 Source code files are divided into lines with line endings of C<\r>,
102 C<\n> or C<\r\n>. Mixing these different line endings causes problems
103 in many text editors and, notably, Module::Signature and GnuPG.
107 Chris Dolan <cdolan@cpan.org>
111 Copyright (C) 2006 Chris Dolan. All rights reserved.
113 This program is free software; you can redistribute it and/or modify
114 it under the same terms as Perl itself.
120 # cperl-indent-level: 4
122 # indent-tabs-mode: nil
123 # c-indentation-style: bsd
125 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :