Firewall-Config-Content

 view release on metacpan or  search on metacpan

lib/Firewall/Config/Content/Static.pm  view on Meta::CPAN

package Firewall::Config::Content::Static;

#------------------------------------------------------------------------------
# 加载扩展模块
#------------------------------------------------------------------------------
use Moose;
use Encode;
use Digest::MD5;
use Firewall::Utils::Date;
use namespace::autoclean;

#------------------------------------------------------------------------------
# 定义 Content::Static 通用属性
#------------------------------------------------------------------------------
has config => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1, );

has confContent => ( is => 'ro', isa => 'Str', lazy => 1, builder => '_buildConfContent', );

has cursor => ( is => 'ro', isa => 'Int', default => 0, );

#------------------------------------------------------------------------------
# 引用 Firewall::Config::Content::Role 角色属性和方法约束
#------------------------------------------------------------------------------
with 'Firewall::Config::Content::Role';

#------------------------------------------------------------------------------
# 改写 confSign 属性并设置懒加载,提供构建方法
#------------------------------------------------------------------------------
has '+confSign' => ( required => 0, lazy => 1, builder => '_buildConfSign', );

has '+timestamp' => ( required => 0, lazy => 1, builder => '_buildTimestamp', );

#------------------------------------------------------------------------------
# 配置文件哈希方法
#------------------------------------------------------------------------------
sub _buildConfSign {
  my $self = shift;
  return Digest::MD5::md5_hex( join( "\n", @{$self->config} ) );
}

#------------------------------------------------------------------------------
# 加载设备配置方法
#------------------------------------------------------------------------------
sub _buildConfContent {
  my $self    = shift;
  my $content = join( "\n", @{$self->config} );
  return $content;
}

#------------------------------------------------------------------------------
# 生成配置时间戳
#------------------------------------------------------------------------------
sub _buildTimestamp {
  my $self = shift;
  return Firewall::Utils::Date->new->getFormatedDate();
}

#------------------------------------------------------------------------------
# 生成配置解析标志位,为每行配置设置初始状态为0
#------------------------------------------------------------------------------
sub _buildLineParsedFlags {
  my $self = shift;
  return ( [ map {0} ( 1 .. @{$self->config} ) ] );
}

#------------------------------------------------------------------------------
# 跳转 Head 头部函数,引入游标的概念
#------------------------------------------------------------------------------
sub goToHead {
  my $self = shift;
  $self->{cursor} = 0;
}

#------------------------------------------------------------------------------
# 跳转 nextLine 函数,跳转下一行



( run in 0.500 second using v1.01-cache-2.11-cpan-39bf76dae61 )