1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm $
3 # $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $
6 ##############################################################################
8 package Perl::Critic::Policy::Miscellanea::RequireRcsKeywords;
15 use List::MoreUtils qw(none);
17 use Perl::Critic::Utils qw{
18 :booleans :characters :severities :data_conversion
21 use base 'Perl::Critic::Policy';
23 our $VERSION = '1.088';
25 #-----------------------------------------------------------------------------
27 Readonly::Scalar my $EXPL => [ 441 ];
29 #-----------------------------------------------------------------------------
31 sub supported_parameters {
35 description => 'The keywords to require in all files.',
36 default_string => $EMPTY,
37 behavior => 'string list',
42 sub default_severity { return $SEVERITY_LOW }
43 sub default_themes { return qw(core pbp cosmetic) }
44 sub applies_to { return 'PPI::Document' }
46 #-----------------------------------------------------------------------------
48 sub initialize_if_enabled {
49 my ($self, $config) = @_;
52 $self->{_keyword_sets} = [
58 [qw(Revision HeadURL Date)],
61 [qw(Revision Source Date)],
64 # Set configuration, if defined.
65 my @keywords = keys %{ $self->{_keywords} };
67 ## no critic ProhibitEmptyQuotes
68 $self->{_keyword_sets} = [ [ @keywords ] ];
74 #-----------------------------------------------------------------------------
77 my ( $self, $elem, $doc ) = @_;
80 my $nodes = $doc->find( \&_wanted );
81 for my $keywordset_ref ( @{ $self->{_keyword_sets} } ) {
83 my $desc = 'RCS keywords '
84 . join( ', ', map {"\$$_\$"} @{$keywordset_ref} )
86 push @viols, $self->violation( $desc, $EXPL, $doc );
89 my @missing_keywords = grep {
90 my $keyword_rx = qr/\$$_.*\$/xms;
92 /$keyword_rx/ ## no critic
97 if (@missing_keywords) {
99 # Provisionally flag a violation. See below.
100 my $desc = 'RCS keywords '
101 . join( ', ', map {"\$$_\$"} @missing_keywords )
103 push @viols, $self->violation( $desc, $EXPL, $doc );
107 # Hey! I'm ignoring @viols for other keyword sets
108 # because this one is complete.
118 my ( undef, $elem ) = @_;
119 return $elem->isa('PPI::Token::Pod')
120 || $elem->isa('PPI::Token::Comment')
121 || $elem->isa('PPI::Token::Quote::Single')
122 || $elem->isa('PPI::Token::Quote::Literal');
129 #-----------------------------------------------------------------------------
137 Perl::Critic::Policy::Miscellanea::RequireRcsKeywords - Put source-control keywords in every file.
141 This Policy is part of the core L<Perl::Critic> distribution.
146 Every code file, no matter how small, should be kept in a
147 source-control repository. Adding the magical RCS keywords to your
148 file helps the reader know where the file comes from, in case he or
149 she needs to modify it. This Policy scans your file for comments that
153 # $Source: /myproject/lib/foo.pm $
155 A common practice is to use the C<Revision> keyword to automatically
156 define the C<$VERSION> variable like this:
158 our ($VERSION) = '$Revision: 2489 $' =~ m{ \$Revision: \s+ (\S+) }x;
162 By default, this policy only requires the C<Revision>, C<Source>, and C<Date>
163 keywords. To specify alternate keywords, specify a value for C<keywords> of a
164 whitespace delimited series of keywords (without the dollar-signs). This would
165 look something like the following in a F<.perlcriticrc> file:
167 [Miscellanea::RequireRcsKeywords]
168 keywords = Revision Source Date Author Id
170 See the documentation on RCS for a list of supported keywords. Many
171 source control systems are descended from RCS, so the keywords
172 supported by CVS and Subversion are probably the same.
176 Jeffrey Ryan Thalhammer <thaljef@cpan.org>
180 Copyright (c) 2005-2008 Jeffrey Ryan Thalhammer. All rights reserved.
182 This program is free software; you can redistribute it and/or modify
183 it under the same terms as Perl itself. The full text of this license
184 can be found in the LICENSE file included with this module.
190 # cperl-indent-level: 4
192 # indent-tabs-mode: nil
193 # c-indentation-style: bsd
195 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :