1
我想解析不同的XML,這是根據類方法中給出的命令返回的......但我想我在這裏變得有點深刻。
我想能夠在XML :: Twig處理程序中使用其他方法和實例的屬性。
這是我在一個木對象定義,以獲得和使用XML解析XML實例方法::嫩枝:
sub get_xmls {
my $self = shift;
my $sehost = shift;
my $symm = shift;
$self->log->info("Getting XMLs for $sehost - $symm");
my %SYMMAPI_CALLS = (
"Config" => {
'command' => "symcfg list -sid ${symm} -v",
'handlers' => {
'SymCLI_ML/Symmetrix' => $self->can('process_symm_info')
},
'dbtable' => "inv_emc_array"
},
"Pools" => {
'command' => "symcfg -sid ${symm} list -pool -thin",
'handlers' => {
'DevicePool' => $self->can('process_symm_pool')
},
'dbtable' => "inv_emc_pool"
}
);
foreach my $key (sort(keys %SYMMAPI_CALLS)) {
my $xmldir = $self->xmlDir;
my $table = $SYMMAPI_CALLS{$key}{'tbl'};
my $handlers = $SYMMAPI_CALLS{$key}{'handlers'};
my $command = $SYMMAPI_CALLS{$key}{'command'};
my $xmlfile = qq(${xmldir}/${sehost}/${key}_${symm}.xml);
$self->log->info("\t$key");
if(!-d qq(${xmldir}/${sehost})) {
mkdir(qq(${xmldir}/${sehost}))
or $self->log->logdie("Cant make dir ${xmldir}/${sehost}: $!");
}
$self->_save_symxml($command, $xmlfile);
$self->twig(new XML::Twig(twig_handlers => $handlers));
$self->log->info("Parsing $xmlfile...");
$self->twig->parsefile($xmlfile);
$self->log->info("\t\t...finished.");
die "Only running the first config case for now...";
}
}
而且處理程序之一的定義(沒有真正做任何事情,現在當我弄清楚如何正確地做到這一點:
sub process_symm_info {
my ($twig, $symminfo) = @_;
print Dumper($symminfo);
}
這一切正常,但我想是爲process_symm_info
方法有機會獲得$自己和所有的方法和屬性$自我與帶來沿這是可能的嗎?我做錯了嗎?Sinc e我可以指定XML的特定部分,因此能夠使用處理程序中的數據來完成其他任務。
這是我第一次冒險進入Perl Moose(如果你不能說明的話)。
當然!這是一個漫長的一天。我認爲我的大腦被炸了。 – 2012-07-30 22:39:50