• 追加された行はこの色です。
  • 削除された行はこの色です。
* アトリビュートの型制約 [#ddb4f265]

*** Num.pm [#j22644c7]
 package Num;
 use Mouse;
 use Mouse::Util::TypeConstraints;
 
 subtype 'PositiveInt'
    => as 'Int'
    => where { $_ > 0 }
    => message { "The number you provided, $_, was not a positive number" };

 has 'num' => (
    is  => 'ro',
    isa => 'PositiveInt',
 );
 
 __PACKAGE__->meta->make_immutable();

*** main.pl [#iaea632a]
my $num = Num->new(num => -10);


** 説明 [#t7acc871]
hasでアトリビュートを記述する際にisaで型制約を指定する事が出来る。


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS