perl-patterns
Solid现代 Perl 5.36+ 的惯用法、最佳实践和约定,用于构建稳健、可维护的 Perl 应用程序。
AI & Automation 201,447 stars
30903 forks Updated yesterday MIT
Install
Quality Score: 95/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# 现代 Perl 开发模式
适用于构建健壮、可维护应用程序的 Perl 5.36+ 惯用模式和最佳实践。
## 何时启用
* 编写新的 Perl 代码或模块时
* 审查 Perl 代码是否符合惯用法时
* 重构遗留 Perl 代码以符合现代标准时
* 设计 Perl 模块架构时
* 将 5.36 之前的代码迁移到现代 Perl 时
## 工作原理
将这些模式作为偏向现代 Perl 5.36+ 默认设置的指南应用:签名、显式模块、聚焦的错误处理和可测试的边界。下面的示例旨在作为起点被复制,然后根据您面前的实际应用程序、依赖栈和部署模型进行调整。
## 核心原则
### 1. 使用 `v5.36` 编译指令
单个 `use v5.36` 即可替代旧的样板代码,并启用严格模式、警告和子程序签名。
```perl
# Good: Modern preamble
use v5.36;
sub greet($name) {
say "Hello, $name!";
}
# Bad: Legacy boilerplate
use strict;
use warnings;
use feature 'say', 'signatures';
no warnings 'experimental::signatures';
sub greet {
my ($name) = @_;
say "Hello, $name!";
}
```
### 2. 子程序签名
使用签名以提高清晰度和自动参数数量检查。
```perl
use v5.36;
# Good: Signatures with defaults
sub connect_db($host, $port = 5432, $timeout = 30) {
# $host is required, others have defaults
return DBI->connect("dbi:Pg:host=$host;port=$port", undef, undef, {
RaiseError => 1,
PrintError => 0,
});
}
# Good: Slurpy parameter for variable args
sub log_message($level, @details) {
say "[$level] " . join(' ', @details);
}
# Bad: Manual argument unpacking
sub connect_db {
my ($host, $port, $timeout) = @_;
$port //= 5432;
$timeout //= 30;
# ...
}
```
### 3. 上下文敏感性
理解标量上下文与列表上下文——这是 Perl 的核心概念。
```perl
use v5.36;
my @items = (1, 2, 3, 4, 5);
my @copy = @items; # List context: all elements
my $count = @items; # Scalar context: count (5)
say "Items: " . scalar @items; # Force scalar co...
Details
- Author
- affaan-m
- Repository
- affaan-m/everything-claude-code
- Created
- 4 months ago
- Last Updated
- yesterday
- Language
- JavaScript
- License
- MIT
Integrates with
Similar Skills
Semantically similar based on skill content — not just same category
Data & Documents Listed
golang-patterns
用于构建健壮、高效且可维护的Go应用程序的惯用Go模式、最佳实践和约定。
5 Updated 1 months ago
Edward-H26 AI & Automation Solid
golang-patterns
Idiomatic Go patterns, best practices, and conventions for building robust, efficient, and maintainable Go applications.
201,447 Updated yesterday
affaan-m AI & Automation Solid
rust-patterns
地道的Rust模式、所有权、错误处理、特质、并发,以及构建安全、高性能应用程序的最佳实践。
201,447 Updated yesterday
affaan-m AI & Automation Solid
perl-security
Comprehensive Perl security covering taint mode, input validation, safe process execution, DBI parameterized queries, web security (XSS/SQLi/CSRF), and perlcritic security policies.
201,447 Updated yesterday
affaan-m AI & Automation Listed
shell-scripting
Bash Shell 脚本编写
1 Updated today
ryukyagamilight