Will,

They're all coding standards. I say leave the Coda where it is, and
put this in the same grouping as 'use warnings' (i.e.
'TestingAndDebugging').
Ok, see attached patch.

Also, instead of checking for "/usr/local" and then reporting a
violation, switch it. Check for the *allowed* version, and, failing
that, report a violation. Then you'll catch /sw/bin/perl, /opt/bin/
perl, C:\perl\bin\perl.exe, and others.
Good idea, annoyed with myself for not having seen that earlier...

This is already tested in t/distro/file_metadata.t.
Thanks for the pointer, and the feedback!

Regards,

Paul
Index: lib/Perl/Critic/Policy/TestingAndDebugging/CheckPerlShebang.pm
===================================================================
--- lib/Perl/Critic/Policy/TestingAndDebugging/CheckPerlShebang.pm	(revision 0)
+++ lib/Perl/Critic/Policy/TestingAndDebugging/CheckPerlShebang.pm	(revision 0)
@@ -0,0 +1,76 @@
+# $Id#
+package Perl::Critic::Policy::TestingAndDebugging::CheckPerlShebang;
+
+use strict;
+use warnings;
+use Perl::Critic::Utils;
+use Perl::Critic::Violation;
+use base 'Perl::Critic::Policy';
+
+our $VERSION = '0.1';
+$VERSION = eval $VERSION;    ## no critic
+
+my $minus_w_desc = q{Need to use 'perl -w' instead of 'use warnings;'};
+my $minus_w_expl = q{All perl source in parrot must 'use warnings;' not the older 'perl -w' usage};
+
+my $spec_desc = q{Found platform-specific perl shebang line};
+my $spec_expl = q{Perl source in parrot should use the platform-independent shebang line: #! perl};
+
+#----------------------------------------------------------------------------
+
+sub default_severity { return $SEVERITY_LOW }
+sub applies_to       { return 'PPI::Document' }
+
+#----------------------------------------------------------------------------
+
+sub violates {
+    my ( $self, $elem, $doc ) = @_;
+
+    my @elements = $doc->children();
+
+    # look for the shebang line, if any
+    foreach my $element ( @elements) {
+        if ($element =~ m/^\#! .*? perl/xgs) {
+            # if the shebang line matches '-w', report the violation
+            if ($element =~ m/-w/gs) {
+                my $sev = $self->get_severity();
+                return Perl::Critic::Violation
+                    ->new( $minus_w_desc, $minus_w_expl, $element, $sev ); 
+            }
+            elsif ($element !~ m/^\#! \s* perl \s*/xgs) {
+                my $sev = $self->get_severity();
+                return Perl::Critic::Violation
+                    ->new( $spec_desc, $spec_expl, $element, $sev ); 
+            }
+            else {
+                last;  # shebang line ok; skip to the end of the elements
+            }
+        }
+    }
+
+    # we didn't find any dodgy shebang lines, so return with success
+    return;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Perl::Critic::Policy::TestingAndDebugging::CheckPerlShebang
+
+=head1 DESCRIPTION
+
+Check to see if the old 'perl -w' shebang line is used to switch on
+warnings.  Also check to see that the perl shebang line isn't unix-specific 
+i.e. uses something like #!/usr/bin/perl instead of the cross-platform #! perl.
+
+=cut
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to