Skip to content

Commit fa9176a

Browse files
committed
refactor: modernize Perl code following perlstyle conventions
- Update .github/copilot-instructions.md with comprehensive Perl style guide - Rename provision.pm -> Provision.pm to follow CamelCase convention - Update package name TorrustDeploy::App::Command::provision -> Provision - Modernize Perl version declarations: use v5.40 instead of separate pragmas - Update all module references in tests and documentation - Verify functionality with successful VM provisioning test Follows perlstyle conventions for consistent, readable code organization.
1 parent a9ba166 commit fa9176a

File tree

7 files changed

+77
-26
lines changed

7 files changed

+77
-26
lines changed

.github/copilot-instructions.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,66 @@ A modern Perl console application for deploying Torrust Tracker to Hetzner Cloud
44

55
## Code Quality Standards
66

7+
### Perl Code Organization
8+
9+
Follow [perlstyle](https://perldoc.perl.org/5.42.0/perlstyle) conventions for consistent, readable code.
10+
11+
#### Core Requirements
12+
13+
- **Always use strict and warnings**: `use strict; use warnings;` or `use v5.36;` (enables both)
14+
- **Modern Perl**: Use `use v5.40;` or higher for modern features (enables strict, warnings, and more)
15+
16+
#### Naming Conventions
17+
18+
- **Package names**: Mixed case starting with capital letter, no underscores
19+
20+
- Example: `TorrustDeploy::App::Command::Provision`
21+
- Lowercase reserved for pragmas (`strict`, `warnings`, `integer`)
22+
23+
- **Variable naming by scope**:
24+
25+
- `$ALL_CAPS_HERE` - constants only
26+
- `$Some_Caps_Here` - package-wide global/static variables
27+
- `$no_caps_here` - function scope `my()` or `local()` variables
28+
29+
- **Function and method names**: All lowercase with underscores
30+
31+
- Example: `$obj->as_string()`, `provision_infrastructure()`
32+
33+
- **Leading underscore**: Indicates private/internal use only
34+
- Example: `_internal_helper()`, `$_private_var`
35+
36+
#### Directory Structure
37+
38+
- **Module directories (`lib/`)**: CamelCase following package names
39+
40+
- Example: `lib/TorrustDeploy/App/Command/Provision.pm`
41+
- Each `::` separator becomes a directory `/` in the filesystem
42+
43+
- **Test directories (`t/`)**: Lowercase with hyphens or underscores
44+
45+
- Example: `t/001-basic.t`, `t/provision-command.t`, `t/integration/tofu-provider.t`
46+
- Follow established Perl testing conventions
47+
48+
- **Standard project directories**: Use lowercase
49+
50+
- `lib/`, `bin/`, `t/`, `xt/`, `share/`, `templates/`, `script/`, `build/`
51+
52+
- **General project directories**: Use lowercase with underscores for separation
53+
- Example: `cloud_init/`, `user_data/`, `config_templates/`
54+
55+
#### Code Style
56+
57+
- **Indentation**: 4-column indent
58+
- **Braces**: Opening curly on same line as keyword, if possible
59+
- **Spacing**:
60+
- Space before opening curly of multi-line BLOCK
61+
- Space around most operators
62+
- Space after each comma
63+
- No space between function name and opening parenthesis
64+
- **Line breaks**: Break long lines after an operator (except `and`/`or`)
65+
- **Clarity**: Use parentheses when in doubt for readability
66+
767
### Markdown Documentation
868

969
- **Linting**: Follow [markdownlint](https://github.com/DavidAnson/markdownlint) conventions

bin/torrust-deploy

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env perl
22

3-
# Set up Perl environment with safety features
4-
use strict; # Enable strict mode - catches common programming errors like undeclared variables
5-
use warnings; # Enable warnings - shows potential issues in the code
6-
use v5.20; # Require Perl version 5.20 or higher for modern language features
3+
# Set up Perl environment with modern features (includes strict and warnings)
4+
use v5.40;
75

86
# Configure module loading
97
use FindBin qw($Bin); # Import FindBin module and get $Bin variable containing this script's directory

lib/TorrustDeploy/App.pm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package TorrustDeploy::App;
22

3-
use strict;
4-
use warnings;
5-
use v5.20;
3+
use v5.40;
64

75
# App::Cmd framework setup - automatically discovers commands in TorrustDeploy::App::Command::*
86
# Commands are found by convention: each .pm file in lib/TorrustDeploy/App/Command/

lib/TorrustDeploy/App/Command/provision.pm renamed to lib/TorrustDeploy/App/Command/Provision.pm

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package TorrustDeploy::App::Command::provision;
1+
package TorrustDeploy::App::Command::Provision;
22

3-
use strict;
4-
use warnings;
5-
use v5.20;
3+
use v5.40;
64

75
use TorrustDeploy::App -command;
86
use TorrustDeploy::Provision::OpenTofu;
@@ -64,9 +62,6 @@ sub execute {
6462

6563
# Show final summary
6664
$self->_show_final_summary($vm_ip);
67-
68-
say "Provisioning completed successfully!";
69-
say "VM is ready at IP: $vm_ip";
7065
}
7166

7267
sub _copy_templates {
@@ -244,7 +239,7 @@ __END__
244239
245240
=head1 NAME
246241
247-
TorrustDeploy::App::Command::provision - Provision Torrust Tracker VM
242+
TorrustDeploy::App::Command::Provision - Provision Torrust Tracker VM
248243
249244
=head1 DESCRIPTION
250245

lib/TorrustDeploy/Provision/OpenTofu.pm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package TorrustDeploy::Provision::OpenTofu;
22

3-
use strict;
4-
use warnings;
5-
use v5.20;
3+
use v5.40;
64

75
use JSON;
86

@@ -71,6 +69,7 @@ sub apply {
7169
die "OpenTofu apply failed with exit code: $result";
7270
}
7371

72+
say "";
7473
say "OpenTofu apply completed successfully.";
7574
}
7675

project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Mlocal
1919
netdev
2020
NOPASSWD
2121
opentofu
22+
perlstyle
2223
plugdev
2324
pwauth
2425
qcow

t/command/provision.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ use lib "$Bin/../../lib";
44
use Path::Tiny qw(path);
55
use File::Temp qw(tempdir);
66

7-
use TorrustDeploy::App::Command::provision;
7+
use TorrustDeploy::App::Command::Provision;
88
use TorrustDeploy::App;
99

1010
subtest 'Provision command module loads correctly' => sub {
11-
ok(TorrustDeploy::App::Command::provision->can('execute'), 'Provision command has execute method');
12-
ok(TorrustDeploy::App::Command::provision->can('abstract'), 'Provision command has abstract method');
13-
ok(TorrustDeploy::App::Command::provision->can('description'), 'Provision command has description method');
11+
ok(TorrustDeploy::App::Command::Provision->can('execute'), 'Provision command has execute method');
12+
ok(TorrustDeploy::App::Command::Provision->can('abstract'), 'Provision command has abstract method');
13+
ok(TorrustDeploy::App::Command::Provision->can('description'), 'Provision command has description method');
1414
};
1515

1616
subtest 'Provision command provides correct metadata' => sub {
17-
is(TorrustDeploy::App::Command::provision->abstract, 'Provision Torrust Tracker VM using OpenTofu', 'Correct abstract');
17+
is(TorrustDeploy::App::Command::Provision->abstract, 'Provision Torrust Tracker VM using OpenTofu', 'Correct abstract');
1818

19-
my $description = TorrustDeploy::App::Command::provision->description;
19+
my $description = TorrustDeploy::App::Command::Provision->description;
2020
like($description, qr/Provision a Torrust Tracker virtual machine/, 'Description mentions VM provisioning');
2121
like($description, qr/OpenTofu/, 'Description mentions OpenTofu');
2222
like($description, qr/libvirt/, 'Description mentions libvirt');
@@ -71,7 +71,7 @@ subtest 'Provision command template copying functionality' => sub {
7171

7272
# Create a mock provision command instance
7373
my $app = TorrustDeploy::App->new;
74-
my $provision_cmd = TorrustDeploy::App::Command::provision->new({
74+
my $provision_cmd = TorrustDeploy::App::Command::Provision->new({
7575
app => $app,
7676
});
7777

@@ -109,7 +109,7 @@ subtest 'Provision command template copying functionality' => sub {
109109

110110
subtest 'Provision command internal methods' => sub {
111111
my $app = TorrustDeploy::App->new;
112-
my $provision_cmd = TorrustDeploy::App::Command::provision->new({
112+
my $provision_cmd = TorrustDeploy::App::Command::Provision->new({
113113
app => $app,
114114
});
115115

0 commit comments

Comments
 (0)