Perl開発支援(Mojolicious/DBI/Carton)。 モダンPerl、perlcritic、Test::Moreでガイド。
/plugin marketplace add sk8metalme/ai-agent-setup/plugin install lang-perl@ai-agent-setupThis skill is limited to using the following tools:
このファイルはPerl開発に特化した設定を定義します。
最新の安定版バージョンは以下の公式ドキュメントを参照してください:
| 技術 | 公式ドキュメント | 用途 |
|---|---|---|
| Perl | Perl Downloads | バージョン確認・ダウンロード |
| Perl Releases | Perl Development | リリース情報 |
| Mojolicious | Mojolicious (MetaCPAN) | 最新版・リリース履歴 |
| Dancer2 | Dancer2 (MetaCPAN) | 最新版・リリース履歴 |
| DBIx::Class | DBIx::Class (MetaCPAN) | 最新版・リリース履歴 |
| Moo | Moo (MetaCPAN) | 最新版・リリース履歴 |
| Carton | Carton (MetaCPAN) | 最新版・リリース履歴 |
最新の安定版バージョンは上記の公式ドキュメントリファレンスで確認してください。
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use feature ':5.32';
# シグネチャを使用
use feature 'signatures';
no warnings 'experimental::signatures';
sub calculate($x, $y) {
return $x + $y;
}
# sayを使用
say "Hello, World!";
# stateで永続的な変数
sub counter {
state $count = 0;
return ++$count;
}
# モダンなWebフレームワーク
package MyApp;
use Mojo::Base 'Mojolicious', -signatures;
sub startup($self) {
my $r = $self->routes;
# RESTfulルート
$r->get('/users')->to('users#index');
$r->post('/users')->to('users#create');
$r->get('/users/:id')->to('users#show');
}
# コントローラー
package MyApp::Controller::Users;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub show($self) {
my $id = $self->param('id');
$self->render(json => {
user => $self->db->get_user($id)
});
}
package MyClass;
use Moo;
use Types::Standard qw(Str Int);
has name => (
is => 'ro',
isa => Str,
required => 1,
);
has age => (
is => 'rw',
isa => Int,
default => 0,
);
sub introduce {
my $self = shift;
return sprintf("私は%s、%d歳です",
$self->name, $self->age);
}
1;
# プレースホルダ付きDBI
my $sth = $dbh->prepare(q{
SELECT * FROM users
WHERE status = ? AND created_at > ?
});
$sth->execute('active', $date);
# DBIx::Class for ORM
my $users = $schema->resultset('User')->search({
status => 'active',
age => { '>' => 18 }
});
グローバルセキュリティポリシーを参照してください。
#!/usr/bin/env -S perl -T
# 互換性重視の場合:
# #!/usr/bin/perl -T
# taintチェックを有効化
# 危険な文字を除去
$input =~ s/[^\w\s-]//g;
# HTML エスケープ
use HTML::Entities;
my $safe = encode_entities($user_input);
# Try::Tiny を使用
use Try::Tiny;
try {
dangerous_operation();
} catch {
warn "エラーが発生しました: $_";
# エラー処理
} finally {
# クリーンアップ
};
# または適切なエラーチェックでeval使用
eval {
risky_code();
1;
} or do {
my $error = $@ || '不明なエラー';
handle_error($error);
};
use Test::More tests => 5;
use Test::Exception;
# 基本的なテスト
ok($result, '結果は真であるべき');
is($actual, $expected, '値が一致するべき');
like($string, qr/pattern/, '文字列がパターンに一致');
# 例外のテスト
dies_ok { dangerous_func() } 'dieするべき';
throws_ok {
validate_input($bad_data)
} qr/Invalid input/, '正しいエラーを投げる';
# 循環参照を避ける
use Scalar::Util 'weaken';
weaken($self->{parent});
# 大きなファイルは行単位で処理
while (<$fh>) {
process_line($_);
}
=encoding utf-8
=head1 名前
MyModule - 簡潔な説明
=head1 概要
use MyModule;
my $obj = MyModule->new();
=head1 説明
モジュールの詳細な説明。
=head1 メソッド
=head2 new
コンストラクタメソッド。
=cut
# cpanm(モジュールインストール)
cpanm Mojolicious
cpanm DBI DBD::mysql
# テスト実行
prove -lv t/
prove -I lib t/
# コード品質チェック
perlcritic lib/
perltidy lib/
# プロファイリング
perl -d:NYTProf script.pl
nytprofhtml
# 依存関係管理(Carton)
carton install
carton exec -- perl script.pl
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.