Skip to content

Commit

Permalink
Add a perltidy and perlcritic.
Browse files Browse the repository at this point in the history
Satisfy perlcritic level 5.
  • Loading branch information
schwern committed Jun 2, 2009
1 parent 98d383e commit aa49298
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
78 changes: 78 additions & 0 deletions .perlcriticrc
@@ -0,0 +1,78 @@
##
### Configure perlcritic display behavior.
###

# Change the default message to show the policy name so we can shut it up if necessary
verbose = %m [%p] at %f line %l, near '%r'\n

# Force perlcritic to use color, even when run through a pager.
color = 1

# Use a pager.
pager = $PAGER


###
### Turn off policies.
###

# Nuthin wrong with the expression form of map and grep.
[-BuiltinFunctions::RequireBlockMap]
[-BuiltinFunctions::RequireBlockGrep]

# We realize that localizing a variable does not retain it's original value,
# thanks.
[-Variables::RequireInitializationForLocalVars]

# I'd rather use a few unnecessary "" then forget to interpolate.
[-ValuesAndExpressions::ProhibitInterpolationOfLiterals]

# Inline POD is more worthwhile than the dubious optimization of putting it
# after the __END__ block
[-Documentation::RequirePodAtEnd]

# No, we're not going to use English.
[-Variables::ProhibitPunctuationVars]

# That's just rediculous
[-ControlStructures::ProhibitPostfixControls]
[-ValuesAndExpressions::ProhibitEmptyQuotes]
[-ValuesAndExpressions::ProhibitNoisyQuotes]

# Test::Builder makes heavy use of local()
[-Variables::ProhibitLocalVars]

# Nuthin wrong with @$foo
[-References::ProhibitDoubleSigils]

# We're going to be doing this a lot
[-Modules::ProhibitMultiplePackages]


###
### Configure policies
###

# Extend the ability to play with @_ to 3 line subroutines.
[Subroutines::RequireArgUnpacking]
short_subroutine_statements = 3

# No tabs ever
[CodeLayout::ProhibitHardTabs]
allow_leading_tabs = 0

# 'no strict "refs"' is ok
[TestingAndDebugging::ProhibitNoStrict]
allow = refs

###
### New policies and options which are not released yet.
###

# "no warnings" is fine as long as it's restricted to one or more categories
[TestingAndDebugging::ProhibitNoWarnings]
allow_with_category_restriction = 1

# Don't need /x on small regexes.
[RegularExpressions::RequireExtendedFormatting]
minimum_regex_length_to_complain_about = 12
17 changes: 17 additions & 0 deletions .perltidyrc
@@ -0,0 +1,17 @@
--maximum-line-length=100 # we have widescreen now
--indent-columns=4
--continuation-indentation=2
--no-opening-sub-brace-on-new-line
--paren-tightness=1
--square-bracket-tightness=1
--brace-tightness=1
--no-space-for-semicolon
--no-outdent-long-quotes
--output-line-ending=unix
--no-outdent-labels
--no-blanks-before-comments
--blanks-before-subs
--blanks-before-blocks
--maximum-consecutive-blank-lines=2 # Allow two blanks between subroutines
--nospace-after-keyword="my local our and or eq ne if else elsif until unless while for foreach return switch case given when"
--want-break-before="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
2 changes: 2 additions & 0 deletions MANIFEST
@@ -1,3 +1,5 @@
.perlcriticrc
.perltidyrc
Build.PL Build.PL
lib/perl5i.pm lib/perl5i.pm
MANIFEST This list of files MANIFEST This list of files
Expand Down
11 changes: 10 additions & 1 deletion lib/perl5i.pm
Expand Up @@ -152,6 +152,7 @@ use base 'autobox::List::Util';
use base 'autobox::Core'; use base 'autobox::Core';
use base 'autobox::dump'; use base 'autobox::dump';


## no critic (Subroutines::RequireArgUnpacking)
sub import { sub import {
my $class = shift; my $class = shift;


Expand Down Expand Up @@ -200,15 +201,19 @@ sub load_in_caller {
my($module, @args) = @$spec; my($module, @args) = @$spec;


load($module); load($module);
## no critic (BuiltinFunctions::ProhibitStringyEval)
eval qq{ eval qq{
package $caller; package $caller;
\$module->import(\@args); \$module->import(\@args);
1; 1;
} or die "Error while perl5i loaded $module => @args: $@"; } or die "Error while perl5i loaded $module => @args: $@";
} }

return;
} }




## no critic (Subroutines::ProhibitSubroutinePrototypes)
sub dt_gmtime (;$) { sub dt_gmtime (;$) {
my $time = @_ ? shift : time; my $time = @_ ? shift : time;
return CORE::gmtime($time) if wantarray; return CORE::gmtime($time) if wantarray;
Expand All @@ -221,6 +226,7 @@ sub dt_gmtime (;$) {
} }




## no critic (Subroutines::ProhibitSubroutinePrototypes)
sub dt_localtime (;$) { sub dt_localtime (;$) {
my $time = @_ ? shift : time; my $time = @_ ? shift : time;
return CORE::localtime($time) if wantarray; return CORE::localtime($time) if wantarray;
Expand All @@ -234,6 +240,7 @@ sub dt_localtime (;$) {
} }




## no critic (Subroutines::ProhibitSubroutinePrototypes)
sub dt_time () { sub dt_time () {
require DateTime::Format::Epoch; require DateTime::Format::Epoch;
state $formatter = DateTime::Format::Epoch->new( state $formatter = DateTime::Format::Epoch->new(
Expand Down Expand Up @@ -343,7 +350,9 @@ sub dt_time () {


use CLASS; use CLASS;


sub new { bless {}, $CLASS } sub new {
return bless {}, $CLASS
}


sub format_datetime { sub format_datetime {
my $self = shift; my $self = shift;
Expand Down

0 comments on commit aa49298

Please sign in to comment.