【问题标题】:Is there the keyword 'with' in Perl?Perl 中有关键字“with”吗?
【发布时间】:2015-12-11 22:07:58
【问题描述】:

在这个文件中

https://github.com/csirtgadgets/massive-octo-spice/blob/develop/src/lib/CIF/Observable/Binary.pm,

我被这句话弄糊涂了

使用“CIF::Observable”;

在第 9 行。Perl 中有关键字“with”吗?它是如何工作的?

package CIF::Observable::Binary;

use strict;
use warnings;

use Mouse;
use Digest::SHA qw/sha256_hex/;

with 'CIF::Observable';

use constant DEFAULT_HASH_TYPE => 'sha256';

has '+otype' => (
default => 'binary',
);  

has 'hash' => (
is      => 'ro',
isa     => 'CIF::Type::Hash',
default => sub { sha256_hex($_[0]->{'observable'}) },
);  

has 'htype' => (
is      => 'ro',
isa     => 'Str',
default => DEFAULT_HASH_TYPE(),
);  

sub process {}
sub understands {
my $self = shift;
my $args = shift;

return unless($args->{'observable'});
return unless($args->{'otype'});
return unless($args->{'otype'} eq 'binary');
return 1;
} 
__PACKAGE__->meta()->make_immutable();

1;

【问题讨论】:

    标签: perl with-statement


    【解决方案1】:

    with 关键字被Mouse 对象系统用来指示正在定义的类使用指定的角色

    MouseMoose 对象系统的简化实现,主要是为了减少基于Moose 的程序预期的长编译时间

    Mouse 中处理角色的方式与Moose 中的几乎相同,Moose::Role documentation 用于两个模块

    【讨论】:

      猜你喜欢
      • 2010-09-21
      • 2011-06-28
      • 2017-11-21
      • 1970-01-01
      • 2010-10-07
      • 2014-07-19
      • 1970-01-01
      • 2013-09-02
      • 2018-09-30
      相关资源
      最近更新 更多