Moops通过以下构造增强了perl语法:
class MyPkg::MyClass {
# ...
}
Run Code Online (Sandbox Code Playgroud)
并增加了通过引入新关键字来声明成员函数签名的可能性,fun并且method:
class MyPkg::MyClass {
method run(ArrayRef $ar){
}
}
Run Code Online (Sandbox Code Playgroud)
我使用vim和tag文件来导航我的代码库,但这些新的关键字是未知的ctags,所以类,函数和方法都没有编入索引.我该如何改善这种情况?
我试图了解lexical_has属性如何在Moops中运行.这个特性来自,Lexical::Accessor并且据我所知,该lexical_has函数能够通过使用标量引用(保留在其中)生成CODE对class可能"词法上具有"的任何属性的引用accessor =>.然后可以使用CODE引用以"强制"范围的方式访问类属性(因为它们是"由内而外"??).但这只是我的猜测和猜测,所以我希望得到一个更好的解释.我也想知道为什么这种方法在以下示例中似乎不起作用:
从Moops介绍中的一个例子开始,我正在创建一个class Car:
use Moops;
class Car {
lexical_has max_speed => (
is => 'rw',
isa => Int,
default => 90,
accessor => \(my $max_speed),
lazy => 1,
);
has fuel => (
is => 'rw',
isa => Int,
);
has speed => (
is => 'rw',
isa => Int,
trigger => method ($new, $old?) {
confess "Cannot travel at a speed of …Run Code Online (Sandbox Code Playgroud) 我的Dancer app模块中有以下代码:
package Deadlands;
use Dancer ':syntax';
use Dice;
our $VERSION = '0.1';
get '/' => sub {
my ($dieQty, $dieType);
$dieQty = param('dieQty');
$dieType = param('dieType');
if (defined $dieQty && defined $dieType) {
return Dice->new(dieType => $dieType, dieQty => $dieQty)->getStandardResult();
}
template 'index';
};
true;
Run Code Online (Sandbox Code Playgroud)
我有一个名为Dice.pm的Moops类,如果用.pl文件测试它就可以正常工作,但是当我尝试通过Web浏览器访问它时,我收到以下错误:找不到对象方法"new"通过包"骰子"(也许你忘了加载"骰子"?).
我可以和Dancer一起做吗?
以下是Dice.pm的相关代码:
use 5.14.3;
use Moops;
class Dice 1.0 {
has dieType => (is => 'rw', isa => Int, required => 1);
has dieQty => (is => 'rw', isa => Int, …Run Code Online (Sandbox Code Playgroud) 我正在使用Moops,我想要这样的工作:
use Moops;
class A {
fun f {
print "yay,f!\n";
}
}
class B extends A {
fun g {
f();
}
}
B->g(); # should print 'yay, f!'
Run Code Online (Sandbox Code Playgroud)
相反,这会产生:
Undefined subroutine &B::f called at static-functions-lexical-scope.pl line 11.
Run Code Online (Sandbox Code Playgroud)
我可以通过继承Exporterin A和一个use语句来"修复"这个B:
class A extends Exporter {
our @EXPORT = qw(f);
fun f {
print "yay,f!\n";
}
}
class B extends A {
use A;
fun g {
f();
}
}
Run Code Online (Sandbox Code Playgroud)
这看起来有点笨拙,但如果 …