our
$VERSION
=
$Lim::VERSION
;
sub
OPT_REQUIRED (){ 0x00000001 }
sub
OPT_SWALLOW (){ 0x00000002 }
sub
OPT_SINGLE (){ 0x00000004 }
our
%OPTIONS
= (
'required'
=> OPT_REQUIRED,
'swallow'
=> OPT_SWALLOW,
'single'
=> OPT_SINGLE
);
sub
new {
my
$this
=
shift
;
my
$class
=
ref
(
$this
) ||
$this
;
my
%args
=
scalar
@_
> 1 ? (
@_
) : (
textual
=>
$_
[0] );
my
$self
= {
options
=> 0
};
if
(
exists
$args
{textual}) {
foreach
(
split
(/\s+/o,
lc
(
$args
{textual}))) {
if
(
exists
$OPTIONS
{
$_
}) {
$self
->{options} |=
$OPTIONS
{
$_
};
}
else
{
confess __PACKAGE__,
': unknown RPC value collection setting "'
.
$_
.
'"'
;
}
}
}
else
{
unless
(
defined
$args
{children} and
ref
(
$args
{children}) eq
'HASH'
) {
confess __PACKAGE__,
': No children specified or invalid'
;
}
$self
->{children} =
$args
{children};
if
(
defined
$args
{options}) {
unless
(
ref
(
$args
{options}) eq
'ARRAY'
) {
confess __PACKAGE__,
': Invalid options specified'
;
}
foreach
(@{
$args
{options}}) {
if
(
exists
$OPTIONS
{
$_
}) {
$self
->{options} |=
$OPTIONS
{
$_
};
}
else
{
confess __PACKAGE__,
': Unknown RPC value collection option "'
.
$_
.
'"'
;
}
}
}
}
bless
$self
,
$class
;
}
sub
DESTROY {
my
(
$self
) =
@_
;
}
sub
children {
$_
[0]->{children};
}
sub
set_children {
if
(
defined
$_
[1] and
ref
(
$_
[1]) eq
'HASH'
) {
$_
[0]->{children} =
$_
[1];
}
$_
[0];
}
sub
required {
$_
[0]->{options} & OPT_REQUIRED ? 1 : 0;
}
sub
swallow {
$_
[0]->{options} & OPT_SWALLOW ? 1 : 0;
}
sub
single {
$_
[0]->{options} & OPT_SINGLE ? 1 : 0;
}
sub
comform {
unless
(
defined
$_
[1]) {
return
0;
}
if
(
$_
[0]->single) {
unless
(
ref
(
$_
[1]) eq
'HASH'
) {
return
0;
}
}
unless
(
ref
(
$_
[1]) eq
'HASH'
or
ref
(
$_
[1]) eq
'ARRAY'
) {
return
0;
}
return
1;
}
1;