我们有一个示例代码,如下所示。是否可以捕获包 FooBar 中调用的所有缺失属性并动态创建它?这有点像 PHP 的__call。
测试.pl
package Person;
use feature qw(say);
use Moo;
has name => (is => "ro");
my $p = Person->new(name => "John");
say $p->name;
# The missing attribute method will be dynamically created when
# invoked even it's not declared in Person.
say $p->lalala;
$ perl test.pl
John
Can't locate object method "lalala" via package "Test" at test.pl line 13.