본문으로 건너뛰기
Skillpedia
일반 코딩280k · #220

perl-patterns

하는 일

이 도구는 Perl 프로그래밍 언어로 최신 방식의 유지보수하기 쉬운 코드를 작성하도록 돕습니다. 코드가 잘 작동하고 다른 프로그래머가 이해하기 쉽도록 모범 사례와 코딩 패턴을 제안합니다.

사용하는 경우

  • ✓새 Perl 프로그램을 작성하기 시작할 때.
  • ✓다른 사람의 코드가 최신 규칙을 따르는지 검토할 때.
  • ✓오래된 코드를 최신 Perl 버전에 맞게 업데이트할 때.

스킬 링크

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/perl-patterns/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/perl-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“이름과 나이를 받고, 나이에는 기본값이 있는 Perl 함수를 어떻게 작성할 수 있을까요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 도구는 코드 작성을 안내하는 규칙과 예시를 적용합니다. 함수 시그니처와 더 나은 오류 처리처럼 최신 Perl 기능을 사용해 코드를 더 명확하고 안전하게 만드는 데 초점을 맞춥니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Modern Perl Development Patterns

Idiomatic Perl 5.36+ patterns and best practices for building robust, maintainable applications.

When to Activate

  • Writing new Perl code or modules
  • Reviewing Perl code for idiom compliance
  • Refactoring legacy Perl to modern standards
  • Designing Perl module architecture
  • Migrating pre-5.36 code to modern Perl

How It Works

Apply these patterns as a bias toward modern Perl 5.36+ defaults: signatures, explicit modules, focused error handling, and testable boundaries. The examples below are meant to be copied as starting points, then tightened for the actual app, dependency stack, and deployment model in front of you.

Core Principles

1. Use v5.36 Pragma

A single use v5.36 replaces the old boilerplate and enables strict, warnings, and subroutine signatures.

# 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. Subroutine Signatures

Use signatures for clarity and automatic arity checking.

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. Context Sensitivity

Understand scalar vs list context — a core Perl concept.

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 context

4. Postfix Dereferencing

Use postfix dereference syntax for readability with nested structures.

use v5.36;

my $data = {
    users => [
        { name => 'Alice', roles => ['admin', 'user'] },
        { name => 'Bob',   roles => ['user'] },
    ],
};

# Good: Postfix dereferencing
my @users = $data->{users}->@*;
my @roles = $data->{users}[0]{roles}->@*;
my %first = $data->{users}[0]->%*;

# Bad: Circumfix dereferencing (harder to read in chains)
my @users = @{ $data->{users} };
my @roles = @{ $data->{users}[0]{roles} };

5. The isa Operator (5.32+)

Infix type-check — replaces blessed($o) && $o->isa('X').

use v5.36;
if ($obj isa 'My::Class') { $obj->do_something }

Error Handling

eval/die Pattern

use v5.36;

sub parse_config($path) {
    my $content = eval { path($path)->slurp_utf8 };
    die "Config error: $@" if $@;
    return decode_json($content);
}

Try::Tiny (Reliable Exception Handling)

use v5.36;
use Try::Tiny;

sub fetch_user($id) {
    my $user = try {
        $db->resultset('User')->find($id)
            // die "User $id not found\n";
    }
    catch {
        warn "Failed to fetch user $id: $_";
        undef;
    };
    return $user;
}

Native try/catch (5.40+)

use v5.40;

sub divide($x, $y) {
    try {
        die "Division by zero" if $y == 0;
        return $x / $y;
    }
    catch ($e) {
        warn "Error: $e";
        return;
    }
}

Modern OO with Moo

Prefer Moo for lightweight, modern OO. Use Moose only when its metaprotocol is needed.

# Good: Moo class
package User;
use Moo;
use Types::Standard qw(Str Int ArrayRef);
use namespace::autoclean;

has name  => (is => 'ro', isa => Str, required => 1);
has email => (is => 'ro', isa => Str, required => 1);
has age   => (is => 'ro', isa => Int, default  => sub { 0 });
has roles => (is => 'ro', isa => ArrayRef[Str], default => sub { [] });

sub is_admin($self) {
    return grep { $_ eq 'admin' } $self->roles->@*;
}

sub greet($self) {
    return "Hello, I'm " . $self->name;
}

1;

# Usage
my $user = User->new(
    name  => 'Alice',
    email => 'alice@example.com',
    roles => ['admin', 'user'],
);

# Bad: Blessed hashref (no validation, no accessors)
package User;
sub new {
    my ($class, %args) = @_;
    return bless \%args, $class;
}
sub name { return $_[0]->{name} }
1;

Moo Roles


…
자주 묻는 질문

‘함수 시그니처’란 무엇인가요?

함수가 어떤 정보를 받을지 정의하는 더 명확한 방법입니다. 입력 양식의 칸처럼 보여서 코드를 읽기 쉽고 실수도 줄여 줍니다.

‘유지보수하기 쉬운 코드’란 무엇을 뜻하나요?

다른 사람이나 나중의 자신이 큰 어려움 없이 이해하고, 수정하고, 고칠 수 있도록 작성된 코드라는 뜻입니다.

‘최신 패턴’을 사용하는 이유는 무엇인가요?

최신 패턴은 보통 보안, 명확성, 효율성이 개선되어 있고 최신 언어 버전과 호환되므로, 새로운 기능의 이점을 누릴 수 있습니다.

상세 정보

작성자의 원본 설명

Modern Perl 5.36+ idioms, best practices, and conventions for building robust, maintainable Perl applications. Use when writing or reviewing modern Perl 5.36+ code.

repo: affaan-m/ECC

인기도

GitHub 스타
280k
순위
#220
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬