$Workflow::Config::XML::VERSION
=
'2.04'
;
my
%XML_OPTIONS
= (
action
=> {
ForceArray
=>
[
'action'
,
'field'
,
'source_list'
,
'param'
,
'validator'
,
'arg'
],
KeyAttr
=> [],
},
condition
=> {
ForceArray
=> [
'condition'
,
'param'
],
KeyAttr
=> [],
},
persister
=> {
ForceArray
=> [
'persister'
],
KeyAttr
=> [],
},
validator
=> {
ForceArray
=> [
'validator'
,
'param'
],
KeyAttr
=> [],
},
workflow
=> {
ForceArray
=> [
'extra_data'
,
'state'
,
'action'
,
'resulting_state'
,
'condition'
,
'observer'
],
KeyAttr
=> [],
},
observer
=> {
ForceArray
=> [
'observer'
],
KeyAttr
=> [],
}
);
my
$XML_REQUIRED
= 0;
sub
parse {
my
(
$self
,
$type
,
@items
) =
@_
;
$self
->_check_config_type(
$type
);
my
@config_items
= Workflow::Config::_expand_refs(
@items
);
return
()
unless
(
scalar
@config_items
);
my
@config
= ();
foreach
my
$item
(
@config_items
) {
my
$file_name
= (
ref
$item
) ?
'[scalar ref]'
:
$item
;
$log
->info(
"Will parse '$type' XML config file '$file_name'"
);
my
$this_config
;
try
{
$this_config
=
$self
->_translate_xml(
$type
,
$item
);
}
catch
(
$error
) {
croak
$log
->error(
"Processing $file_name: "
,
$error
);
}
$log
->info(
"Parsed XML '$file_name' ok"
);
my
$outer_tag
=
$self
->get_config_type_tag(
$type
);
if
(
ref
$this_config
->{
$outer_tag
} eq
'ARRAY'
) {
$log
->debug(
"Adding multiple configurations for '$type'"
);
push
@config
, @{
$this_config
->{
$outer_tag
} };
}
else
{
$log
->debug(
"Adding single configuration for '$type'"
);
push
@config
,
$this_config
;
}
}
return
@config
;
}
sub
_translate_xml {
my
(
$self
,
$type
,
$config
) =
@_
;
unless
(
$XML_REQUIRED
) {
try
{
}
catch
(
$error
) {
configuration_error
"XML::Simple must be installed to parse "
,
"configuration files/data in XML format"
;
}
XML::Simple->
import
(
':strict'
);
$XML_REQUIRED
++;
}
my
$options
=
$XML_OPTIONS
{
$type
} || {};
my
$data
= XMLin(
$config
, %{
$options
} );
return
$data
;
}
1;