not return a true value at sample.pl line 3. BEGIN failed--compilation aborted at sample.pl line 3. package Acme::AnaTofuZ; use strict; use warnings; sub hello { print "hello" }
true value at sample.pl line 3. BEGIN failed--compilation aborted at sample.pl line 3. package Acme::AnaTofuZ; use strict; use warnings; sub hello { print "hello" } 1;
my sub subject($a, $b) { add($a, $b) } is subject(1, 2), 3; is subject(4, 5), 6; }; • 最新版 subtest 'add' => sub { my $subject = sub ($a, $b) { add($a, $b) } is $subject->(1, 2), 3; is $subject->(4, 5), 6; };
# id の配列からユーザを取得する # returns: HashRef[id => Model::UserAccount] sub find_by_ids { args my $class => 'ClassName', my $db => 'AnaTofuZ::DBFactory', my $ids => 'ArrayRef[Int]';
コメント文化からはギャップがある ◦ 別のアプローチでの返り値チェック機能を実装 43 use Function::Return; use Types::Standard -types; sub foo :Return(Int) { 123 } sub bar :Return(Int) { 3.14 }
Map[PositiveInt,InstanceOf['Model::UserAccount']]; sub find_by_ids { args my $class => 'ClassName', my $db => 'AnaTofuZ::DBFactory', my $ids => 'ArrayRef[Int]';
Dict[]; use constant Comic => Str & sub { $_ eq 'comic' }; use constant Media => Movie | Comic; sub to_label { my $self = shift; state $kind_to_label = compile_match_on_type( Movie, sub { '映画化' }, Comic, sub { '漫画化' }, ); $kind_to_label->($self->kind); #映画化 or 漫画家 }