Blame SOURCES/Perl-Critic-More-1.000-Miscellanea::RequireRcsKeywords.patch

f8fed1
--- Changes
f8fed1
+++ Changes
f8fed1
@@ -14,6 +14,8 @@
f8fed1
      Policy moved:
f8fed1
      * ValuesAndExpressions::ProhibitMagicNumbers has been moved into the
f8fed1
        core Perl::Critic distribution.
f8fed1
+     * Miscellanea::RequireRcsKeywords has been moved here from the core
f8fed1
+       Perl::Critic distribution (RT #69546).
f8fed1
 
f8fed1
      Dependencies:
f8fed1
      * Now requires Perl::Critic 1.082.
f8fed1
--- lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm
f8fed1
+++ lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm
f8fed1
@@ -0,0 +1,202 @@
f8fed1
+##############################################################################
f8fed1
+#      $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/distributions/Perl-Critic/lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm $
f8fed1
+#     $Date: 2011-12-21 14:40:10 -0800 (Wed, 21 Dec 2011) $
f8fed1
+#   $Author: thaljef $
f8fed1
+# $Revision: 4106 $
f8fed1
+##############################################################################
f8fed1
+
f8fed1
+package Perl::Critic::Policy::Miscellanea::RequireRcsKeywords;
f8fed1
+
f8fed1
+use 5.006001;
f8fed1
+use strict;
f8fed1
+use warnings;
f8fed1
+use Readonly;
f8fed1
+
f8fed1
+use List::MoreUtils qw(none);
f8fed1
+
f8fed1
+use Perl::Critic::Utils qw{
f8fed1
+    :booleans :characters :severities :data_conversion
f8fed1
+};
f8fed1
+
f8fed1
+use base 'Perl::Critic::Policy';
f8fed1
+
f8fed1
+our $VERSION = '1.000';
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+Readonly::Scalar my $EXPL => [ 441 ];
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+sub supported_parameters {
f8fed1
+    return (
f8fed1
+        {
f8fed1
+            name            => 'keywords',
f8fed1
+            description     => 'The keywords to require in all files.',
f8fed1
+            default_string  => $EMPTY,
f8fed1
+            behavior        => 'string list',
f8fed1
+        },
f8fed1
+    );
f8fed1
+}
f8fed1
+
f8fed1
+sub default_severity  { return $SEVERITY_LOW              }
f8fed1
+sub default_themes    { return qw(core more pbp cosmetic) }
f8fed1
+sub applies_to        { return 'PPI::Document'            }
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+sub initialize_if_enabled {
f8fed1
+    my ($self, $config) = @_;
f8fed1
+
f8fed1
+    # Any of these lists
f8fed1
+    $self->{_keyword_sets} = [
f8fed1
+
f8fed1
+        # Minimal svk/svn
f8fed1
+        [qw(Id)],
f8fed1
+
f8fed1
+        # Expansive svk/svn
f8fed1
+        [qw(Revision HeadURL Date)],
f8fed1
+
f8fed1
+        # cvs?
f8fed1
+        [qw(Revision Source Date)],
f8fed1
+    ];
f8fed1
+
f8fed1
+    # Set configuration, if defined.
f8fed1
+    my @keywords = keys %{ $self->{_keywords} };
f8fed1
+    if ( @keywords ) {
f8fed1
+        $self->{_keyword_sets} = [ [ @keywords ] ];
f8fed1
+    }
f8fed1
+
f8fed1
+    return $TRUE;
f8fed1
+}
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+sub violates {
f8fed1
+    my ( $self, $elem, $doc ) = @_;
f8fed1
+    my @viols = ();
f8fed1
+
f8fed1
+    my $nodes = $self->_find_wanted_nodes($doc);
f8fed1
+    for my $keywordset_ref ( @{ $self->{_keyword_sets} } ) {
f8fed1
+        if ( not $nodes ) {
f8fed1
+            my $desc = 'RCS keywords '
f8fed1
+                . join( ', ', map {"\$$_\$"} @{$keywordset_ref} )
f8fed1
+                . ' not found';
f8fed1
+            push @viols, $self->violation( $desc, $EXPL, $doc );
f8fed1
+        }
f8fed1
+        else {
f8fed1
+            my @missing_keywords =
f8fed1
+                grep
f8fed1
+                    {
f8fed1
+                        my $keyword_rx = qr< \$ $_ .* \$ >xms;
f8fed1
+                        ! ! none { m/$keyword_rx/xms } @{$nodes}
f8fed1
+                    }
f8fed1
+                    @{$keywordset_ref};
f8fed1
+
f8fed1
+            if (@missing_keywords) {
f8fed1
+                # Provisionally flag a violation. See below.
f8fed1
+                my $desc =
f8fed1
+                    'RCS keywords '
f8fed1
+                        . join( ', ', map {"\$$_\$"} @missing_keywords )
f8fed1
+                        . ' not found';
f8fed1
+                push @viols, $self->violation( $desc, $EXPL, $doc );
f8fed1
+            }
f8fed1
+            else {
f8fed1
+                # Hey! I'm ignoring @viols for other keyword sets
f8fed1
+                # because this one is complete.
f8fed1
+                return;
f8fed1
+            }
f8fed1
+        }
f8fed1
+    }
f8fed1
+
f8fed1
+    return @viols;
f8fed1
+}
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+sub _find_wanted_nodes {
f8fed1
+    my ( $self, $doc ) = @_;
f8fed1
+    my @wanted_types = qw(Pod Comment Quote::Single Quote::Literal End);
f8fed1
+    my @found =  map { @{ $doc->find("PPI::Token::$_") || [] } } @wanted_types;
f8fed1
+    push @found, grep { $_->content() =~ m/ \A qw\$ [^\$]* \$ \z /smx } @{
f8fed1
+        $doc->find('PPI::Token::QuoteLike::Words') || [] };
f8fed1
+    return @found ? \@found : $EMPTY;  # Behave like PPI::Node::find()
f8fed1
+}
f8fed1
+
f8fed1
+1;
f8fed1
+
f8fed1
+__END__
f8fed1
+
f8fed1
+#-----------------------------------------------------------------------------
f8fed1
+
f8fed1
+=pod
f8fed1
+
f8fed1
+=for stopwords RCS
f8fed1
+
f8fed1
+=head1 NAME
f8fed1
+
f8fed1
+Perl::Critic::Policy::Miscellanea::RequireRcsKeywords - Put source-control keywords in every file.
f8fed1
+
f8fed1
+
f8fed1
+=head1 AFFILIATION
f8fed1
+
f8fed1
+This Policy is part of the core L<Perl::Critic|Perl::Critic>
f8fed1
+distribution.
f8fed1
+
f8fed1
+
f8fed1
+=head1 DESCRIPTION
f8fed1
+
f8fed1
+Every code file, no matter how small, should be kept in a
f8fed1
+source-control repository.  Adding the magical RCS keywords to your
f8fed1
+file helps the reader know where the file comes from, in case he or
f8fed1
+she needs to modify it.  This Policy scans your file for comments that
f8fed1
+look like this:
f8fed1
+
f8fed1
+    # $Revision: 4106 $
f8fed1
+    # $Source: /myproject/lib/foo.pm $
f8fed1
+
f8fed1
+A common practice is to use the C<Revision> keyword to automatically
f8fed1
+define the C<$VERSION> variable like this:
f8fed1
+
f8fed1
+    our ($VERSION) = '$Revision: 4106 $' =~ m{ \$Revision: \s+ (\S+) }x;
f8fed1
+
f8fed1
+
f8fed1
+=head1 CONFIGURATION
f8fed1
+
f8fed1
+By default, this policy only requires the C<Revision>, C<Source>, and
f8fed1
+C<Date> keywords.  To specify alternate keywords, specify a value for
f8fed1
+C<keywords> of a whitespace delimited series of keywords (without the
f8fed1
+dollar-signs).  This would look something like the following in a
f8fed1
+F<.perlcriticrc> file:
f8fed1
+
f8fed1
+    [Miscellanea::RequireRcsKeywords]
f8fed1
+    keywords = Revision Source Date Author Id
f8fed1
+
f8fed1
+See the documentation on RCS for a list of supported keywords.  Many
f8fed1
+source control systems are descended from RCS, so the keywords
f8fed1
+supported by CVS and Subversion are probably the same.
f8fed1
+
f8fed1
+
f8fed1
+=head1 AUTHOR
f8fed1
+
f8fed1
+Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
f8fed1
+
f8fed1
+
f8fed1
+=head1 COPYRIGHT
f8fed1
+
f8fed1
+Copyright (c) 2005-2011 Imaginative Software Systems.  All rights reserved.
f8fed1
+
f8fed1
+This program is free software; you can redistribute it and/or modify
f8fed1
+it under the same terms as Perl itself.  The full text of this license
f8fed1
+can be found in the LICENSE file included with this module.
f8fed1
+
f8fed1
+=cut
f8fed1
+
f8fed1
+# Local Variables:
f8fed1
+#   mode: cperl
f8fed1
+#   cperl-indent-level: 4
f8fed1
+#   fill-column: 78
f8fed1
+#   indent-tabs-mode: nil
f8fed1
+#   c-indentation-style: bsd
f8fed1
+# End:
f8fed1
+# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
f8fed1
--- MANIFEST
f8fed1
+++ MANIFEST
f8fed1
@@ -4,6 +4,7 @@ lib/Perl/Critic/More.pm
f8fed1
 lib/Perl/Critic/Policy/CodeLayout/RequireASCII.pm
f8fed1
 lib/Perl/Critic/Policy/Editor/RequireEmacsFileVariables.pm
f8fed1
 lib/Perl/Critic/Policy/ErrorHandling/RequireUseOfExceptions.pm
f8fed1
+lib/Perl/Critic/Policy/Miscellanea/RequireRcsKeywords.pm
f8fed1
 lib/Perl/Critic/Policy/Modules/PerlMinimumVersion.pm
f8fed1
 lib/Perl/Critic/Policy/Modules/RequirePerlVersion.pm
f8fed1
 lib/Perl/Critic/Policy/ValuesAndExpressions/RestrictLongStrings.pm
f8fed1
--- t/99_pod_coverage.t
f8fed1
+++ t/99_pod_coverage.t
f8fed1
@@ -49,6 +49,7 @@ sub get_trusted_methods {
f8fed1
         applies_to
f8fed1
         default_themes
f8fed1
         default_severity
f8fed1
+        initialize_if_enabled
f8fed1
         supported_parameters
f8fed1
     );
f8fed1
 }