Login
Tweaked behavior of -top option to give some more flexibility
[gknop/Perl-Critic.git] / lib / Perl / Critic / Policy / CodeLayout / RequireTidyCode.pm
CommitLineData
dff08b70
JRT
1#######################################################################
2# $URL$
3# $Date$
4# $Author$
5# $Revision$
6########################################################################
7
59b05e08
JRT
8package Perl::Critic::Policy::CodeLayout::RequireTidyCode;
9
10use strict;
11use warnings;
bf159007 12use English qw(-no_match_vars);
59b05e08
JRT
13use Perl::Critic::Utils;
14use Perl::Critic::Violation;
15use base 'Perl::Critic::Policy';
16
d56f8418 17our $VERSION = '0.13_01';
59b05e08
JRT
18$VERSION = eval $VERSION; ## no critic
19
dff08b70
JRT
20#----------------------------------------------------------------------------
21
59b05e08 22my $desc = q{Code is not tidy};
5dc3db7a 23my $expl = [ 33 ];
59b05e08
JRT
24
25#----------------------------------------------------------------------------
26
9f1d5408 27sub default_severity { return $SEVERITY_LOWEST }
dff08b70
JRT
28sub applies_to { return 'PPI::Document' }
29
30#----------------------------------------------------------------------------
59b05e08
JRT
31
32sub violates {
33 my ( $self, $elem, $doc ) = @_;
bf159007
JRT
34
35 # If Perl::Tidy is missing, silently pass this test
36 eval { require Perl::Tidy; };
37 return if $EVAL_ERROR;
59b05e08
JRT
38
39 my $source = "$doc";
40 my $dest = $EMPTY;
59b05e08
JRT
41 my $stderr = $EMPTY;
42
ee99f507
JRT
43 # Perl::Tidy gets confused by @ARGV.
44 local @ARGV = (); ## no critic
45
59b05e08
JRT
46 Perl::Tidy::perltidy(
47 source => \$source,
48 destination => \$dest,
49 stderr => \$stderr,
59b05e08
JRT
50 );
51
52 if ($stderr) {
53
54 # Looks like perltidy had problems
55 $desc = q{perltidy had errors!!};
56 }
57
47639f94 58 if ( $source ne $dest ) {
5dc3db7a
JRT
59
60 return Perl::Critic::Violation->new( $desc,
61 $expl,
62 [ 0, 0 ],
63 $self->get_severity(), );
59b05e08
JRT
64 }
65
66 return; #ok!
67}
68
691;
70
71__END__
72
73=pod
74
75=head1 NAME
76
77Perl::Critic::Policy::CodeLayout::RequireTidyCode
78
79=head1 DESCRIPTION
80
81Conway does make specific recommendations for whitespace and
82curly-braces in your code, but the most important thing is to adopt a
83consistent layout, regardless of the specifics. And the easiest way
84to do that is to use L<Perl::Tidy>. This policy will complain if
85you're code hasn't been run through Perl::Tidy.
86
87=head1 NOTES
88
89Since L<Perl::Tidy> is not widely deployed, this is the only policy in
90the L<Perl::Critic> distribution that is not enabled by default. To
91enable it, put this line in your F<.perlcriticrc> file:
92
93 [CodeLayout::RequireTidyCode]
94
95=head1 SEE ALSO
96
97L<Perl::Tidy>
98
99
100=head1 AUTHOR
101
102Jeffrey Ryan Thalhammer <thaljef@cpan.org>
103
104=head1 COPYRIGHT
105
106Copyright (c) 2005 Jeffrey Ryan Thalhammer. All rights reserved.
107
108This program is free software; you can redistribute it and/or modify
109it under the same terms as Perl itself. The full text of this license
110can be found in the LICENSE file included with this module.
111
112=cut