This may be expanded on, but is currently a bullet list of code guidelines and suggestions for working on whatbot core. Failure to follow these without adequate explanation opens you up to ridicule and abuse. These are suggestions, and open for debate.
- This is not 1978, we don't need to conserve whitespace and line feeds to save disk space. Your code should be readable.
- "Tabs" should actually be four spaces. This conversion is not yet complete.
- In blocks, such as if, while, and foreach, the opening bracket should be on the same line as the statement.
if ( $boo == 1 ) {
- Strings without interpolation should always be in single quotes.
- Any set of parameters to a function, or anything in parenthesis after an if/while/for/foreach block should have spaces between the parens and the items, unless the item is singular and simple. So, a simple scalar like $foo does not require spaces, but $foo{'bar'} or $foo eq 'bar' would require spaces.
# Correct if ( $foo eq 'bar' ) { } if ($bar) {} while ( $foobar =~ /(foo|bar)/ ) {} $self->call($function); # Incorrect if ($bar eq 'foo') {} while ( $bar );
- Subroutine arguments should be filled by @_, and the parenthesis should always have a space between the arguments.
sub foo { my ( $self, $foo ) = @_; }
- Hash keys should also always be enclosed in single quotes, unless they are a Moose accessor definition.
$hash{'value'}; $hash_ref->{'value'};
- Each subroutine or method call should have parens following, even if no arguments are being passed, unless they are an accessor.
- Each module should have this order:
- Header
- Package declaration
- use Moose;
- 'extends' if necessary
- Imported modules
- VERSION statement if necessary
- Moose Accessors
- Code
########################################################################### # whatbot/Module.pm ########################################################################### # the whatbot project - http://www.whatbot.org ########################################################################### package whatbot::Module; use Moose; extends 'whatbot'; use DBI; use Digest::SHA1; use WWW::Mechanize; has 'foo' => ( is => 'rw', isa => 'Int' ); sub bar { $self->whee(); } 1;
