Skip to content

Commit

Permalink
Add ADR and code changes for minimal Perl code layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuelsmann committed Jan 3, 2025
1 parent 6e98ab1 commit 37e22e8
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 68 deletions.
1 change: 0 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ requires 'Email::MessageID';
requires 'Email::Sender::Simple';
requires 'Email::Sender', '2.601'; # 2.601 adds 'sasl_authenticator'
requires 'Email::Stuffer';
requires 'Feature::Compat::Try';
requires 'File::Find::Rule';
requires 'Hash::Merge';
requires 'HTML::Entities';
Expand Down
61 changes: 61 additions & 0 deletions doc/adr/0102-perl-pragmas-top-declarations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 0101 Perl pragma declarations on top of file

Date: 2025-01-03

## Status

Draft

## Context

The `use` statement in Perl is used for two distinct purposes. The most
straight forward being loading of dependency modules (e.g., `use LedgerSMB;`).
The other purpose is to enable "pragmas" (e.g. `use strict;`); these change
Perl's behaviour in the scope in which they are declared.

Traditionally, Perl pragmas have been declared after the opening `package`
line in a module; like this:

```perl
package LedgerSMB::PGDate;

use Moose;

use strict;
use warnings;

...

1;
```

In recent years, syntax was added to Perl which depends on the correct pragmas
to be enabled (or on older Perls compatibility modules to be loaded); e.g.:

```perl
use v5.40;

class LedgerSMB::PGDate {
...
}
```

## Decision

1. Pragmas such as `utf8`, `warnings`, `strict`, `vX.YY` (minimum Perl version
requirement declaration) should be declared
*before* the first line of of code (e.g. the `package` declaration)
2. Modules which modify or enhance syntax, such as `Syntax::*`, `Feature::Compat::*`
and `Object::Pad`, should be declared *after* the pragmas and before the
`package` or `class` declarations
3. All regular module dependencies need to be declared *after* the `package`
declaration
4. All code in `lib/`, `t/` and `xt/` must declare the minimum Perl version using
the `vX.YY` syntax.

## Consequences



## Annotations

9 changes: 4 additions & 5 deletions lib/LedgerSMB/Admin/Command/backup.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::backup;

=head1 NAME
Expand All @@ -7,18 +11,13 @@ LedgerSMB::Admin::Command::backup - ledgersmb-admin 'backup' command
=cut

use strict;
use warnings;

use LedgerSMB::Admin::Command;
use LedgerSMB::Database;

use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;


sub run {
my ($self, $dbname, $filename) = @_;
Expand Down
9 changes: 4 additions & 5 deletions lib/LedgerSMB/Admin/Command/copy.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::copy;

=head1 NAME
Expand All @@ -7,18 +11,13 @@ LedgerSMB::Admin::Command::copy - ledgersmb-admin 'copy' command
=cut

use strict;
use warnings;

use LedgerSMB::Admin::Command;
use LedgerSMB::Database;

use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;

sub run {
my ($self, $dbname, $newname) = @_;

Expand Down
8 changes: 4 additions & 4 deletions lib/LedgerSMB/Admin/Command/create.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::create;

=head1 NAME
Expand All @@ -7,9 +11,6 @@ LedgerSMB::Admin::Command::create - ledgersmb-admin 'create' command
=cut

use strict;
use warnings;

use LedgerSMB::Admin::Command;
use LedgerSMB::Database;

Expand All @@ -18,7 +19,6 @@ extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Getopt::Long qw(GetOptionsFromArray);
use Feature::Compat::Try;

has options => (is => 'ro', default => sub { {} });

Expand Down
9 changes: 4 additions & 5 deletions lib/LedgerSMB/Admin/Command/destroy.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::destroy;

=head1 NAME
Expand All @@ -7,18 +11,13 @@ LedgerSMB::Admin::Command::destroy - ledgersmb-admin 'destroy' command
=cut

use strict;
use warnings;

use LedgerSMB::Admin::Command;
use LedgerSMB::Database;

use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;

my $logger;

sub run {
Expand Down
9 changes: 5 additions & 4 deletions lib/LedgerSMB/Admin/Command/restore.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::restore;

=head1 NAME
Expand All @@ -6,8 +11,6 @@ LedgerSMB::Admin::Command::restore - ledgersmb-admin 'restore' command
=cut

use strict;
use warnings;
use version;

use File::Temp;
Expand All @@ -19,8 +22,6 @@ use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;

my $schema = 'public';

sub _option_spec {
Expand Down
9 changes: 4 additions & 5 deletions lib/LedgerSMB/Admin/Command/upgrade.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::upgrade;

=head1 NAME
Expand All @@ -7,9 +11,6 @@ LedgerSMB::Admin::Command::upgrade - ledgersmb-admin 'upgrade' command
=cut

use strict;
use warnings;

use Getopt::Long qw(GetOptionsFromArray);
use LedgerSMB::Admin::Command;
use LedgerSMB::Database;
Expand All @@ -18,8 +19,6 @@ use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;

has modules_only => (is => 'ro');

sub run {
Expand Down
10 changes: 5 additions & 5 deletions lib/LedgerSMB/Admin/Command/user.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Admin::Command::user;

=head1 NAME
Expand All @@ -6,9 +11,6 @@ LedgerSMB::Admin::Command::user - ledgersmb-admin 'user' command
=cut

use strict;
use warnings;

use Getopt::Long qw(GetOptionsFromArray);
use LedgerSMB::Admin::Command;
use LedgerSMB::App_State;
Expand All @@ -25,8 +27,6 @@ use Moose;
extends 'LedgerSMB::Admin::Command';
use namespace::autoclean;

use Feature::Compat::Try;

has options => (is => 'ro', default => sub { {} });

sub _get_valid_salutation {
Expand Down
8 changes: 5 additions & 3 deletions lib/LedgerSMB/FileFormats/ISO20022/CAMT053.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package LedgerSMB::FileFormats::ISO20022::CAMT053;
use strict;

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::FileFormats::ISO20022::CAMT053;

use XML::LibXML;
use XML::LibXML::XPathContext;
use Feature::Compat::Try;

=head1 NAME
Expand Down
8 changes: 5 additions & 3 deletions lib/LedgerSMB/FileFormats/OFX/BankStatement.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package LedgerSMB::FileFormats::OFX::BankStatement;

use v5.36;
use experimental 'try';
use warnings;
use strict;
use Feature::Compat::Try;

package LedgerSMB::FileFormats::OFX::BankStatement;

use XML::LibXML;

=head1 NAME
Expand Down
5 changes: 4 additions & 1 deletion lib/LedgerSMB/PSGI.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

use v5.36;
use experimental 'try';

package LedgerSMB::PSGI;

=head1 NAME
Expand Down Expand Up @@ -49,7 +53,6 @@ use Log::Any;
use Log::Log4perl;
use Scalar::Util qw{ reftype };
use String::Random;
use Feature::Compat::Try;

# To build the URL space
use Plack;
Expand Down
8 changes: 4 additions & 4 deletions lib/LedgerSMB/Scripts/account.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Scripts::account;

=head1 NAME
Expand All @@ -19,11 +23,7 @@ maintainable.
=cut

use strict;
use warnings;

use Log::Any;
use Feature::Compat::Try;

use LedgerSMB;

Expand Down
8 changes: 3 additions & 5 deletions lib/LedgerSMB/Scripts/contact.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Scripts::contact;

Expand All @@ -15,11 +18,6 @@ This module is the UI controller for the customer, vendor, etc functions; it
=cut

use v5.36.1;
use warnings;

use Feature::Compat::Try;

use LedgerSMB;
use LedgerSMB::Entity::Company;
use LedgerSMB::Entity::Person;
Expand Down
8 changes: 4 additions & 4 deletions lib/LedgerSMB/Scripts/import_csv.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Scripts::import_csv;

=head1 NAME
Expand All @@ -16,11 +20,7 @@ This module doesn't specify any methods.
=cut

use strict;
use warnings;

use JSON::PP;
use Feature::Compat::Try;

use LedgerSMB::AA;
use LedgerSMB::Batch;
Expand Down
7 changes: 4 additions & 3 deletions lib/LedgerSMB/Scripts/setup.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

use v5.36;
use experimental 'try';
use warnings;

package LedgerSMB::Scripts::setup;

=head1 NAME
Expand All @@ -22,8 +26,6 @@ management tasks.
# these are maintained inside the LedgerSMB::Database package.
#

use strict;
use warnings;
use version;

use Carp;
Expand All @@ -35,7 +37,6 @@ use HTTP::Status qw( HTTP_OK HTTP_INTERNAL_SERVER_ERROR HTTP_UNAUTHORIZED );
use Log::Any;
use MIME::Base64;
use Scope::Guard;
use Feature::Compat::Try;

use LedgerSMB;
use LedgerSMB::App_State;
Expand Down
Loading

0 comments on commit 37e22e8

Please sign in to comment.