Lib-Pepper

 view release on metacpan or  search on metacpan

codingstyle.md  view on Meta::CPAN

**When the Singular Form is Awkward:**

Some words don't have natural singular forms, so use descriptive names:

```perl
# Instead of @datum → $datum (awkward)
my @dataPoints;
foreach my $point (@dataPoints) { ... }

# Instead of @information → $information (same)
my @infoItems;
foreach my $item (@infoItems) { ... }

# Already singular words
my @settings;
foreach my $setting (@settings) { ... }  # "setting" is already singular-ish
```

**Compound Names:**

```perl
my @sourceFiles;
foreach my $sourceFile (@sourceFiles) { ... }

my @userPermissions;
foreach my $userPermission (@userPermissions) { ... }

my @fileNames;
foreach my $fileName (@fileNames) { ... }
```

**Anonymous Iteration (when item not used):**

```perl
# When you just need to iterate N times
for(1..10) {
    do_something();
}

for(1..$count) {
    push @array, generate_item();
}

# Incrementing counters
$counter++ for(@items);
```

### Subroutines and Methods

**Rule:** Use camelCase with the first letter lowercase. **Avoid underscores** in function names.

**Examples:**
```perl
sub loadConfig { ... }
sub getSessionId { ... }
sub validateSession { ... }
sub createCookie { ... }
sub handleChildStart { ... }
sub getSettings { ... }
sub checkDBH { ... }
sub updateConfig { ... }
sub newClacksFromConfig { ... }
```

**Single-word function names:**
```perl
sub init { ... }
sub reload { ... }
sub register { ... }
sub get { ... }
sub set { ... }
sub delete { ... }
```

**Exception - Private Methods/Functions:**

Private or internal functions may use a leading underscore:
```perl
sub _getColumnType { ... }     # Private helper method
sub _logfromjs { ... }          # Internal logging function
sub _getLocalIPs { ... }        # Private utility function
```

**Note:** The leading underscore indicates the function is internal and should not be called from outside the module.

**Method Parameters:**

Modern Perl signatures are used:
```perl
sub functionName($self, $param1, $param2) {
    # function body
}
```

For methods:
```perl
sub methodName($self, $arg1, $arg2, %options) {
    # method body
}
```

First parameter is always `$self` for methods, `$class` for constructors.

**Parameter Naming:**
```perl
sub processUser($self, $userId, $userName, $isActive) {
    # Parameters use camelCase
}
```

### Constants

**Rule:** Use `Readonly` module for constants with UPPERCASE names:

```perl
use Readonly;
Readonly::Scalar my $BLOBMODE => 0x00020000;
```

**Note:** For constants with hexadecimal notation, Perl Critic may require explicit annotation:
```perl



( run in 1.306 second using v1.01-cache-2.11-cpan-39bf76dae61 )