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