metamod:perl_code_style

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
metamod:perl_code_style [2010-07-12 07:19:48]
oysteint created
metamod:perl_code_style [2022-05-31 09:29:32] (current)
Line 1: Line 1:
-====== Perltidy configuration ======+====== Coding guidelines ======
  
-The following Perltidy configuration can be used as a guideline for formatting the code in Metamod.+These rules apply to perl and php, unless otherwise mentioned.
  
 +===== General rules =====
 +
 +  * spaces instead of tabs
 +  * indent is 4 spaces
 +  * cuddled else:<code>
 +if ($a > $b) {
 +    $a++;
 +} else {
 +    $b++;
 +}
 +</code>
 +  * Line-length: usually <80 characters, not more than 120 chars
 +  * translate parameter from @_ to names in start of sub
 +
 +==== Documentation ====
 +
 +  * POD(perl)/Doxygen(php) API documentation for modules, close to code
 +  * POD(perl) documentation for scripts (pod2usage)
 +
 +==== Name-convention ====
 +
 +  * variables: lower case, underscore splits words
 +  * constants: upper case, underscore splits words
 +  * functions: lower case, underscore splits words
 +  * modules/classes: upper case first, camel case splits words
 +
 +===== Perltidy configuration =====
 +
 +The following Perltidy configuration can be used as a guideline for formatting the code in Metamod.
 +//Don't use perl-tidy blindly on code in particular on others code! Use perltidy for diff.//
 <code> <code>
 # make some defaults explicit to document the decision # make some defaults explicit to document the decision
Line 22: Line 52:
 --closing-token-indentation=0 --closing-token-indentation=0
 </code> </code>
 +
 +===== Perl Template =====
 +
 +==== Basic module template ====
 +
 +This is a template for basic module.
 +<code perl>
 +package <package name>;
 +
 +=begin LICENSE
 +
 +METAMOD is free software; you can redistribute it and/or modify
 +it under the terms of the GNU General Public License as published by
 +the Free Software Foundation; either version 2 of the License, or
 +(at your option) any later version.
 +
 +METAMOD is distributed in the hope that it will be useful,
 +but WITHOUT ANY WARRANTY; without even the implied warranty of
 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 +GNU General Public License for more details.
 +
 +You should have received a copy of the GNU General Public License
 +along with METAMOD; if not, write to the Free Software
 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 +
 +=end LICENSE
 +
 +=cut
 +
 +use strict;
 +use warnings;
 +
 +=head1 NAME
 +
 +<package name> - <description>
 +
 +=head1 SYNOPSIS
 +
 +=head1 DESCRIPTION
 +
 +=head1 FUNCTIONS/METHODS
 +
 +=cut
 +
 +<your code goes here>
 +
 +=head1 LICENSE
 +
 +GPLv2 L<http://www.gnu.org/licenses/gpl-2.0.html>
 +
 +=cut
 +1;
 +</code>
 +
 +==== Catalyst controller template ====
 +
 +This template can be used for new Catalyst controllers.
 +
 +<code perl>
 +package <package name>;
 +
 +=begin LICENSE
 +
 +METAMOD is free software; you can redistribute it and/or modify
 +it under the terms of the GNU General Public License as published by
 +the Free Software Foundation; either version 2 of the License, or
 +(at your option) any later version.
 +
 +METAMOD is distributed in the hope that it will be useful,
 +but WITHOUT ANY WARRANTY; without even the implied warranty of
 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 +GNU General Public License for more details.
 +
 +You should have received a copy of the GNU General Public License
 +along with METAMOD; if not, write to the Free Software
 +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 +
 +=end LICENSE
 +
 +=cut
 +
 +BEGIN {extends 'MetamodWeb::BaseController::Base'; }
 +
 +=head1 NAME
 +
 +<package name> - <description>
 +
 +=head1 DESCRIPTION
 +
 +=head1 METHODS
 +
 +=cut
 +
 +=head2 auto
 +
 +=cut
 +
 +sub auto :Private {
 +    my ( $self, $c ) = @_;
 +
 +    # Controller specific initialisation for each request.
 +}
 +
 +=head2 index
 +
 +
 +=cut
 +sub index : Path("replace with absolute path") {
 +    my ( $self, $c ) = @_;
 +
 +}
 +
 +
 +#
 +# Remove comment if you want a controller specific begin(). This
 +# will override the less specific begin()
 +#
 +#sub begin {
 +#    my ( $self, $c ) = @_;    
 +#}
 +
 +#
 +# Remove comment if you want a controller specific end(). This
 +# will override the less specific end()
 +#
 +#sub end {
 +#    my ( $self, $c ) = @_;
 +#}
 +
 +
 +__PACKAGE__->meta->make_immutable;
 +
 +=head1 LICENSE
 +
 +GPLv2 L<http://www.gnu.org/licenses/gpl-2.0.html>
 +
 +=cut
 +
 +1;
 +</code>
 +
 +==== Script ====
 +
 +FIXME
 +
 +===== PHP Template =====
 +
 +FIXME
 +
 +
 +
 +
 +
  • metamod/perl_code_style.1278919188.txt.gz
  • Last modified: 2022-05-31 09:23:19
  • (external edit)