Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Code::Police

by Ovid (Cardinal)
on Aug 01, 2001 at 19:41 UTC ( [id://101421]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info Ovid
Description:

This is the Code::Police module. Provide this module to programmers who fail to use strict and most of their coding errors will be instantly eliminated.

################################
package Code::Police;
################################
$Code::Police::VERSION = 2.1828;
# Last updated August 1, 2001
#
# Module:       Code::Police
# Author:       Ovid
# Date Created: August 1, 2001
# Purpose:      This is the Code::Police module.  Provide this module 
+to programmers who fail
#               to use strict and most of their coding errors will be 
+instantly eliminated.
# --------------- Maintenance log ------------------------
# Date:
# Programmer:
# Action:
# --------------------------------------------------------
INIT{if(!exists$INC{'strict.pm'}){unlink((caller)[1])}}
"Ovid";
__END__

=head1 NAME

Code::Police - Enforce rigorous coding standards

=head1 SYNOPSIS

 #!/usr/bin/perl
 use Code::Police;
 
=head1 DESCRIPTION

This is the Code::Police module.  Provide this module to programmers w
+ho fail
to use strict and most of their coding errors will be instantly elimin
+ated.

=head1 COPYRIGHT

Copyright (c) 2001 Ovid.  All rights reserved.
This program is free software; you may redistribute it and/or modify i
+t under 
the same terms as Perl itself

Ovid assumes absolutely no responsibility for any of this dreck.  If y
+ou use this,
you will rot in the 8th circle of Hell for all of eternity.

=head1 AUTHOR

Ovid <dev@null.com>
Address bug reports and comments to dev@null.com.  When sending bug re
+ports,
please provide the version of Code::Police, the version of Perl, and t
+he version 
of the operating system you are using.

=head1 MISCELLANEOUS

Why are you reading this?  No one actually B<reads> POD.  You must be 
+a loser.  If you
have to rely on the documentation to figure out what something does, y
+ou're probably one
of those wimps who uses strict.  Screw documentation.  Do what you alw
+ays do and ask someone
else how it works.

This was inspired by an offhand joke by merlyn L<merlyn@stonehenge.com
+> at a Damian
Conway talk.  He is, however, not responsible for this and shouldn't b
+e held liable if
you're a bonehead.

=head1 BUGS

August 1, 2001: Currently, this program will not work if any other mod
+ule is loaded that
uses strict.  I could have tried to code around that by using a bunch 
+of evals or something,
but so what?  It's a joke.

=cut
Replies are listed 'Best First'.
Re: Code::Police
by tachyon (Chancellor) on Aug 02, 2001 at 01:46 UTC

    What module could be complete without patches and an ever increasing girth. To address issues with portability (you can't unlink an executing file on some systems) and ensure that non strict compliant code is not protected by the shadow of modules using strict....

    package Code::Police; ################################ $Code::Police::VERSION = 2.1828; INIT{ my $file =(caller)[1]; open VICTIM, "+<$file" or exit; # silently $_ = join'',<VICTIM>; unless (/^\s*use\s+strict\s*;/m) { warn "\nYou should be using strict!\n\n"; sleep 2; warn "Here's a fleeting last glimpse!\n\n"; sleep 2; print; print "\nDo you apologise for not using strict?"; chomp(my $plea = <>); unless ($plea eq "use strict or die;") { warn "Not good enough!\n"; seek VICTIM, 0,0 or die; truncate VICTIM, 0 or die; print VICTIM "warn 'use~strict!';\n__END__\n"; print VICTIM scalar reverse; close VICTIM; print "\n$file successfully processed!\n"; } } } "tachyon";

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Now suppose I do this:
      #!/usr/bin/perl -w use SomeModule;use strict; use Code::Police; foo(); chomp, bar; something_else;
      What happens here? The use strict is invisible to the Code::Police, and so tpircs ym yfisdrawkcab yeht.

      Now, what if I do this?

      #!/usr/bin/perl -w use Code::Police; BEGIN { eval '#' . <<''; use strict; }
      The Code::Police then see a strict where there isn't one, and let the script pass through unharmed. The original way of detecting strict I think is probably better.
Re: Code::Police
by arturo (Vicar) on Aug 01, 2001 at 21:59 UTC

    Ovid, this module fails to work as advertised. I tried it on a colleague and it eliminated *all* of his coding errors. Could you update the documentation?

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

      It is quite possible that a programmer using this module could have all coding errors eliminated. However, if they write their own modules and use them (admittedly doubtful if they need this utility), then those other modules will not be corrected by this module. Hence my statement that it will correct most of the errors.

      Just glad I can be of service to the community.

      Cheers,
      Ovid

      Vote for paco!

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://101421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-12-11 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (63 votes). Check out past polls.