Perl中是否有关键字'with'?

时间:2015-12-11 03:59:47

标签: perl with-statement

在此档案中

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;

1 个答案:

答案 0 :(得分:6)

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

MouseMoose对象系统的简化实现,主要用于减少基于Moose的程序所需的长编译时间

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