App-Context

 view release on metacpan or  search on metacpan

lib/App/perlstyle.pod  view on Meta::CPAN

    if (-d $file) {         # $file is a directory
        # ...
    } elsif (-l _) {        # $file is a symlink
        # ...
    }

Package names begin with a capital letter in each word, followed by
lower case letters.

    App::Standard          # good
    App::Authz             # good
    App::MainCode          # good

Use all lower case for POD files which are documentation only.

    App::styleguide        # good for doc only

Naming for modules should be according to the following general rules.

    All App services which have *broad* support from the 
        p5ee@perl.org list would go into the "App" package
    Naming style is similar to other modules on CPAN
    Naming choice draws from precedent of other modules on CPAN
    Naming choice draws from precedent of J2EE

Packages which aren't intended to be instantiated as objects may
have an "adjective" or "concept" for a name
(i.e. App::Standard).  Packages which are
Modules/Classes and are intended to be instantiated as objects
should be nouns, potentially accompanied by modifying adjectives
(i.e. App::Authen::Principal).

=head2 Indents

Code checked into CVS must never contain tabs.
Patches of code with tabs do not email well, and different people
have their tabstops set different ways.
If you want to set tab stops on your editor, just make sure it
converts tabs to spaces when it saves the file.

Indentation for normal block-style coding should be 4 spaces. 
The settings for Emacs and vim are as follows.

=over

=item * x?emacs: cperl-mode

  .xemacs/custom.el:
  ------------------
  (custom-set-variables
     '(cperl-indent-level 4)
     '(cperl-continued-statement-offset 4)
     '(cperl-tab-always-indent t)
     '(indent-tabs-mode nil)
  )

=item * vim

  .vimrc:
  -------
  set expandtab " replaces any tab keypress with the appropriate number of spaces
  set tabstop=4 " sets tabs to 4 spaces

=back

=head2 Line Lengths

Maximum line lengths should be 77 columns (or 75 columns for
an unbroken line of characters).
This is for maximum portability to different people's
development environments and for decent transmission
through e-mail to a wide array of e-mail clients
(i.e. for patches).

Example: Eudora 3.0.6 wraps a solid, single line of 80 non-whitespace
characters (i.e. ######...#####) at character 76.  If there are
spaces in the line, it allows lines up to character 78 before wrapping
the last words down to the next line.  If sources have no more than
77 characters in a line, a "diff -u" patch will add a column, and the
lines will escape being folded.

=head2 Blank Space

No space before a semicolon that closes a statement.

    foo(@bar) ;     # wrong
    foo(@bar);      # right

Line up corresponding items vertically.

    my $foo   = 1;
    my $bar   = 2;
    my $xyzzy = 3;

    open(FILE, $fh)   or die $!;
    open(FILE2, $fh2) or die $!;

    $rot13 =~ tr[abcedfghijklmnopqrstuvwxyz]
                [nopqrstuvwxyzabcdefghijklm];

    # note we use a-mn-z instead of a-z,
    # for readability
    $rot13 =~ tr[a-mn-z]
                [n-za-m];

Put blank lines where they make sense for readability, such as
the following.
Put blank lines between groups of code that do different things.  Put
blank lines after your variable declarations.  Put a blank line before a
final return() statement.  Put a blank line following a block (and
before, with the exception of comment lines).

An example:

    # this is my function!
    sub foo {
        my (@data) = @_;
        my $obj = new Constructor;
        my ($var1, $var2);

        $obj->setFoo($data[1]);



( run in 2.665 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )