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 tabs. 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 );
- Hash keys should also always be enclosed in single quotes, unless they are a Moose accessor definition.
$hash{'value'}; $hash_ref->{'value'};
Declarative Syntax
In every class except for the whatbot::Command namespace, Moops should be used. This will look a little different from normal Perl, but provides some readability. The class structure should look something like:
###########################################################################
# Example.pm
# the whatbot project - http://www.whatbot.org
###########################################################################
use Moops;
=head1 NAME
whatbot::Example - This is an example class.
=head1 DESCRIPTION
This module is an example.
=head1 SYNOPSIS
my $foo = whatbot::Example->new();
$foo->bar();
=head1 PUBLIC METHODS
=over 4
=cut
class whatbot::Example extends whatbot::Component {
=item bar( $foo )
Bars the foo.
=cut
method bar( Foo $foo ) {
#no op
return $foo;
}
}
1;
=pod
=back
=head1 LICENSE/COPYRIGHT
Be excellent to each other and party on, dudes.
=cut
Subroutines and Methods
- If in a non-Declare class, subroutine arguments should be filled by @_, and the parenthesis should always have a space between the arguments.
sub foo { my ( $self, $foo ) = @_; }
- Each subroutine or method call should have parens following, even if no arguments are being passed, unless they are an accessor.
Class Structure
Each class/module should have this approximate order:
- Header
- use Moops;
- VERSION statement if necessary
- Class definition
- Imported modules
- Moose Accessors
- Code
Example:
# whatbot/Module.pm
use Moops;
class Whatbot::Module extends Whatbot {
use Digest::SHA1;
use WWW::Mechanize;
has 'foo' => ( is => 'rw', isa => 'Int' );
method bar() {
$self->whee();
}
}
1;