Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Mooseのコンストラクタでのみ設定できる属性を作成することは可能ですか? 私はこのようなことをしたいと思います:
my $foo = new Foo(file => 'foo.txt'); my $bar = new Foo(string => $str); $foo->file('baz.txt'); # dies
コンストラクターで設定できない属性を作成できることはわかっていますが、補完的なケースが欠落しているようです。
それは単なる読み取り専用属性ではありませんか? 私が書いたら
package Foo; use Moose; has 'file' => (is => 'ro', isa => 'Str'); has 'string' => (is => 'rw', isa => 'Str'); 1;
その後、あなたのコードは
Cannot assign a value to a read-only accessor