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

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