2025年秋のPerl
Kenichi Ishigaki
@charsbar
YAPC::Fukuoka 2025
Nov 14, 2025
Slide 2
Slide 2 text
me
2016年のPerl@LLoT
Perl in 2016@YAPC::Hokkaido
2017年春のPerl@YAPC::Kansai
2017年夏のPerl@YAPC::Fukuoka
(萬國之津梁@YAPC::Okinawa)
(2018年初夏のPerl5)@Hokkaido.pm #14
2018年夏のPerl5@Shibuya.pm #18
2018年残暑のPerl@LL2018
2019年冬のPerl@YAPC::Tokyo
(Learn Languages 2021)
2023年春のPerl@YAPC::Kyoto
2024年冬のPerl@YAPC::Hiroshima
2024年秋のPerl@YAPC::Hakodate
2025年秋のPerl@YAPC::Fukuoka <- イマココ
Slide 3
Slide 3 text
Perl Toolchain Summit 2025
• 5月1日~5月4日
• 今年はライプツィヒで開催
• Japan Perl Association が
今年もスポンサーに
(ありがとうございます)
https://charsbar.hatenadiary.org/entry/2025/06/15/201905
Slide 4
Slide 4 text
Perl Foundation のお財布事情
TPF理事を務めていた野崎さんによる情報公開
https://blogs.perl.org/users/makoto_nozaki/2024/10/understanding-the-financials-of-the-perl-and-raku-foundation-tprf.html
Slide 5
Slide 5 text
Perl Foundation のお財布事情
支出と収入の内訳
https://blogs.perl.org/users/makoto_nozaki/2024/10/understanding-the-financials-of-the-perl-and-raku-foundation-tprf.html
Slide 6
Slide 6 text
Perl Foundation のお財布事情
過去と現在のスポンサーページの比較
https://perlfoundation.org/our-donors.html
https://perlfoundation.org/past-sponsors.html
CORE::chdir
chdirをCORE付きで呼び出せるようになりました
use experimental 'class';
class MyClass {
method chdir {
my $path = shift;
&CORE::chdir($path) or return;
say STDERR "CHDIR TO $path";
}
}
Slide 11
Slide 11 text
source::encoding
ソースコードのエンコーディングを強制できるようになりました
use source::encoding 'ascii';
say 'あああ'; # コンパイルエラー
Slide 12
Slide 12 text
source::encoding
use v5.42 (以降)で(ほかにも何もしなければ)
アスキー文字が強制されます
use v5.42;
say 'あああ'; # コンパイルエラー
Slide 13
Slide 13 text
source::encoding
コメントや POD でも容赦しません
use v5.42;
# コメントで回避できる? # NG
=pod
NAME 取り扱い説明書 # NG
=cut
Slide 14
Slide 14 text
source::encoding
__DATA__ や __END__ 以降は OK ですが…
use v5.42;
# ASCII ONLY
__END__
=pod
NAME 取扱説明書 # OK
=cut
Slide 15
Slide 15 text
source::encoding
日本語を使う場合は忘れずに use utf8; を
use v5.42;
use utf8;
Slide 16
Slide 16 text
source::encoding
スクリプトなどでそのまま日本語を出力する際には
一手間必要になるのもお忘れなく
use v5.42;
use utf8;
STDOUT->binmode('utf8’);
# または use Encode して適宜encode
Slide 17
Slide 17 text
source::encoding
指定できるのは ascii と utf8 のみ
use source::encoding 'utf8';
# ≒ use utf8;
# use encoding 'cp932';
Slide 18
Slide 18 text
source::encoding
no source::encoding で強制を解除できます
use v5.42;
no source::encoding;
say 'あああ'; # utf8 でなくても OK
Slide 19
Slide 19 text
source::encoding
特定のスコープのみの指定・解除もできます
use v5.42;
package Foo {
no source::encoding;
say 'あああ'; # OK
}
# say 'あああ'; # NG
Slide 20
Slide 20 text
アポストロフィとパッケージ
5.41.3で一度は禁止されることになったのですが…
use v5.41.3;
package Acme::Don't;
# Invalid version format
Slide 21
Slide 21 text
アポストロフィとパッケージ
悪影響が大きすぎるということで撤回されました
package Acme::Don't; # OK
もう消すこともできないということで廃止の警告も解除されています
Slide 22
Slide 22 text
アポストロフィとパッケージ
ただし、use v5.42 (以降)すると使えなくなります
use v5.42;
package Acme::Don't;
# Invalid version format (non-numeric data)
Slide 23
Slide 23 text
アポストロフィとパッケージ
明示的に許可することはできます
(が、おすすめしません)
use v5.42;
use feature 'apostrophe_as_package_separator';
package Acme::Don't;
Slide 24
Slide 24 text
アポストロフィとパッケージ
特定のスコープでのみ有効にすることもできます
use v5.42;
use Test::More;
subtest 'Foo' => sub {
use feature 'apostrophe_as_package_separator';
isn't $x => $y; # いまは isnt で
};
done_testing;
Slide 25
Slide 25 text
スマートマッチ
十年以上も警告無しには使えず、削除予定でした
use v5.18;
use experimental qw(smartmatch switch);
say $foo ~~ $bar;
given ($foo) {
when (undef) { say '$foo is undefined' }
default { say '$foo is something else' }
}
スマートマッチ
こちらも結局削除予定は撤回されました
featureガードは従来通りですが、実験扱いも終了
use feature qw(smartmatch switch);
say $foo ~~ $bar;
given ($foo) {
when (undef) { say '$foo is undefined' }
default { say '$foo is something else' }
}
Slide 28
Slide 28 text
スマートマッチ
ただし、use v5.42 (以降)だけでは使えません
use v5.42;
say $foo ~~ $bar; # エラー
given ($foo) { # エラー
when (undef) { say '$foo is undefined' }
default { say '$foo is something else' }
}
Slide 29
Slide 29 text
スマートマッチ
どうしても必要なら明示的に許可してください
use v5.42;
use feature qw(smartmatch switch);
say $foo ~~ $bar;
given ($foo) {
when (undef) { say '$foo is undefined' }
default { say '$foo is something else' }
}
Slide 30
Slide 30 text
any / all 演算子
効率を気にしなければ grep を使えばよいのですが…
use Test::More;
# どれかひとつでも定義されていればOK
ok grep {defined $_} @foo;
# すべて定義されていればOK
ok !grep {!defined $_} @foo;
done_testing;
Slide 31
Slide 31 text
any / all 演算子
従来は List::Util が定番
use Test::More;
use List::Util qw(any all);
# または List::MoreUtils qw(any all)
ok any {defined $_} @foo;
ok all {defined $_} @foo;
done_testing;
Slide 32
Slide 32 text
any / all 演算子
5.42で実験的なキーワードが用意されました
use v5.42;
use Test::More;
use experimental qw(keyword_any keyword_all);
ok any {defined $_} @foo;
ok all {defined $_} @foo;
done_testing;
Slide 33
Slide 33 text
any / all 演算子
keyword_ がついているのは混乱防止
use Test::More;
use feature ':all';
×use feature 'all';
○use feature 'keyword_all';
Slide 34
Slide 34 text
any / all 演算子
any は List::Util より高速です
use v5.42;
use experimental qw(keyword_any);
use List::Util;
use Benchmark qw(cmpthese);
my @foo = (1..100000);
cmpthese(10000, {
grep => sub { grep {defined $_} @foo },
l_u => sub { List::Util::any {defined $_} @foo },
any => sub { any {defined $_} @foo },
});
Rate grep l_u any
grep 300/s -- -81% -90%
l_u 1565/s 422% -- -47%
any 2941/s 881% 88% --
Slide 35
Slide 35 text
any / all 演算子
all はまだ残念な感じ
use v5.42;
use experimental qw(keyword_all);
use List::Util;
use Benchmark qw(cmpthese);
my @foo = (1..100000);
cmpthese(10000, {
grep => sub { !grep {!defined $_} @foo },
l_u => sub { List::Util::all {defined $_} @foo },
all => sub { all {defined $_} @foo },
});
Rate all grep l_u
all 226/s -- -26% -38%
grep 305/s 35% -- -17%
l_u 365/s 62% 20% --
新しい警告
Perlは無意味な変数などを見つけると警告を出します
my $x; # OK
$x; # NG (警告)
Slide 42
Slide 42 text
新しい警告
5.42では連鎖比較も警告を出すようになりました
use v5.42;
if (0 < $x < 10) { ... } # OK
0 < $x < 10; # NG (警告)
Slide 43
Slide 43 text
:writer
:reader属性は5.40でコア入りしました
use v5.40;
use experimental qw(class);
class Author {
field $name :param :reader;
}
my $author = Author->new(name => 'me');
say $author->name;
Slide 44
Slide 44 text
:writer
5.42で :writer 属性もコア入りしました
use v5.42;
use experimental qw(class);
class Author {
field $name :param :reader :writer;
}
my $author = Author->new(name => 'me');
$author->set_name('Ishigaki');
say $author->name;
Slide 45
Slide 45 text
:writer
メソッドチェーンにも対応しています
use v5.42;
use experimental qw(class);
class Point {
field $x :param :reader :writer;
field $y :param :reader :writer;
}
my $point = Point->new(x => 10, y => 10);
$point->set_x(20)->set_y(20);
Slide 46
Slide 46 text
:writer
必要ならメソッド名を変更できます
use v5.42;
use experimental qw(class);
class Author {
field $name :param :reader :writer(change_name);
}
my $author = Author->new(name => 'me');
$author->change_name('Ishigaki');
say $author->name;
Slide 47
Slide 47 text
:writer
ただし、readerと同じメソッド名にはできません
use v5.42;
use experimental qw(class);
class Author {
# Method name redefined が発生します
field $name :param :reader :writer(name);
}
my $author = Author->new(name => 'me');
$author->name('Ishigaki');
# Too few arguments for subroutine
×say $author->name;
Slide 48
Slide 48 text
:writer
いまはまだスカラーのみの対応です
use v5.42;
use experimental qw(class);
class Author {
field $name :param :reader :writer;
field @modules ×:param :reader ×:writer;
method set_modules(@new) { @modules = @new }
}
Slide 49
Slide 49 text
プライベートメソッド
メソッドを隠蔽したいとき
package Foo;
sub do_something {
my $self = shift;
...
$self->_error_check(@_);
}
sub _error_check { ... }
Slide 50
Slide 50 text
プライベートメソッド
無名関数で隠蔽する手もありますが…
package Foo;
sub do_something {
my $self = shift;
my $error_check = sub { ... };
...
$error_check->(@_);
}
Slide 51
Slide 51 text
プライベートメソッド
名前をつければ解決?
package Foo;
use Sub::Util qw(subname);
sub do_something {
my $self = shift;
my $error_check =
subname error_check => sub { ... };
...
$error_check->(@_);
}
Slide 52
Slide 52 text
プライベートメソッド
5.18 からはレキシカルサブルーチンで
package Foo;
use v5.18;
use experimental 'lexical_sub'; # 5.26まで
sub do_something {
my $self = shift;
my sub error_check { ... };
...
error_check(@_);
}
Slide 53
Slide 53 text
プライベートメソッド
ただし、微妙な制約もありました
package Foo;
use v5.26;
my sub error_check { ... }
sub do_something {
my $self = shift;
...
×$self->error_check(@_);
○error_check($self, @_);
}
Slide 54
Slide 54 text
プライベートメソッド
5.42 で method にも my を適用できるように
use v5.42;
use experimental 'class';
class Foo {
my method error_check { ... }
}
Slide 55
Slide 55 text
プライベートメソッド
呼び出すときは ->& で
use v5.42;
use experimental 'class';
class Foo {
my method error_check { ... }
method do_something {
...
$self->&error_check(@_);
}
}
Slide 56
Slide 56 text
プライベートメソッド
->& は my sub にも適用できます
package Foo;
use v5.42;
my sub error_check { ... }
sub do_something {
my $self = shift;
...
$self->&error_check(@_);
}
Slide 57
Slide 57 text
CVE-2024-56406
tr/// に脆弱性が見つかっています
my $foo = "¥x{FF}" x 1000000;
$foo =~ tr/¥xFF/¥x{100}/;
対象は 5.34 から 5.40 まで
Perl Steering Council
2025年8月にメンバーの入れ替えがありました
• Paul Evans
• Leon Timmermans (new)
• Aristotle Pagaltzis
Slide 62
Slide 62 text
エラー時に表示される method 引数の数 (5.43.2)
従来は暗黙の $self を抜いた数が表示されていました
use v5.42;
use experimental 'class';
class Foo {
method bar ($x, $y) { ... }
}
my $foo = Foo->new;
$foo->bar;
# Too few arguments for subroutine 'Foo::bar' (got 0; expected 2)
Slide 63
Slide 63 text
エラー時に表示される method 引数の数 (5.43.2)
5.43.2からは暗黙の $self を含んだ数になります
use v5.43.2;
use experimental 'class';
class Foo {
method bar ($x, $y) { ... }
}
my $foo = Foo->new;
$foo->bar;
# Too few arguments for subroutine 'Foo::bar' (got 1; expected 3)