Login
Importing Perl-Critic-0.13.
[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;
5use Perl::Tidy;
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
18sub new {
19 my ( $class, %args ) = shift;
20 my $self = bless {}, $class;
21 $self->{_tested} = 0;
22 return $self;
23}
24
25sub violates {
26 my ( $self, $elem, $doc ) = @_;
27 return if $self->{_tested}; #Only test this once!
28 $self->{_tested} = 1;
29
30 my $source = "$doc";
31 my $dest = $EMPTY;
32 my $logfile = $EMPTY;
33 my $errfile = $EMPTY;
34 my $stderr = $EMPTY;
35
36 Perl::Tidy::perltidy(
37 source => \$source,
38 destination => \$dest,
39 stderr => \$stderr,
40 logfile => \$logfile,
41 errorfile => \$errfile
42 );
43
44 if ($stderr) {
45
46 # Looks like perltidy had problems
47 $desc = q{perltidy had errors!!};
48 }
49
50 if ( $source eq $dest ) {
51 return Perl::Critic::Violation->new( $desc, $expl, [ 0, 0 ] );
52 }
53
54 return; #ok!
55}
56
571;
58
59__END__
60
61=pod
62
63=head1 NAME
64
65Perl::Critic::Policy::CodeLayout::RequireTidyCode
66
67=head1 DESCRIPTION
68
69Conway does make specific recommendations for whitespace and
70curly-braces in your code, but the most important thing is to adopt a
71consistent layout, regardless of the specifics. And the easiest way
72to do that is to use L<Perl::Tidy>. This policy will complain if
73you're code hasn't been run through Perl::Tidy.
74
75=head1 NOTES
76
77Since L<Perl::Tidy> is not widely deployed, this is the only policy in
78the L<Perl::Critic> distribution that is not enabled by default. To
79enable it, put this line in your F<.perlcriticrc> file:
80
81 [CodeLayout::RequireTidyCode]
82
83=head1 SEE ALSO
84
85L<Perl::Tidy>
86
87
88=head1 AUTHOR
89
90Jeffrey Ryan Thalhammer <thaljef@cpan.org>
91
92=head1 COPYRIGHT
93
94Copyright (c) 2005 Jeffrey Ryan Thalhammer. All rights reserved.
95
96This program is free software; you can redistribute it and/or modify
97it under the same terms as Perl itself. The full text of this license
98can be found in the LICENSE file included with this module.
99
100=cut