アトリビュート生成

hasを使う。

User.pm

 package User;
 use Mouse;
 use URI;
 
 has 'name' => ( is => 'rw', isa => 'Str' );
 has 'age'  => ( is => 'rw', isa => 'Int' );
 has 'uri'  => ( is => 'rw', isa => 'URI' );
 
 __PACKAGE__->meta->make_immutable();
 1;

main.pl

 use User;
 use URI;
 
 my $user = User->new( name => 'taro', age => 10, uri => URI->new('http://example.com/') );
 say $user->name;
 say $user->age;
 say $user->uri;

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