has
'content'
=> (
is
=>
'rw'
,
isa
=>
'ArrayRef'
,
default
=>
sub
{ [ ] },
traits
=> [
qw( Array )
],
trigger
=>
sub
{
my
(
$self
,
$content
) =
@_
;
map
{
confess
'cannot add undefined value to '
.
$self
if
!
$_
;
$_
->set_parent(
$self
);
}
@$content
;
},
handles
=> {
_add_content
=>
'push'
,
children
=>
'elements'
,
}
);
sub
BUILD {
my
(
$self
) =
@_
;
for
my
$child
( @{
$self
->content} ) {
$child
->set_parent(
$self
);
}
}
sub
BUILDARGS {
my
$class
=
shift
;
my
%args
=
@_
== 1 && is_HashRef(
$_
[0] ) ? %{
$_
[0]} :
@_
;
for
my
$att
(
qw(border_width resize_mode)
) {
$args
{properties}{
$att
} =
delete
$args
{
$att
}
if
exists
$args
{
$att
};
}
__PACKAGE__->SUPER::BUILDARGS(
%args
);
}
after
'_build_gobject'
=>
sub
{
my
$self
=
shift
;
for
( @{
$self
->content} ) {
$_
->set_parent(
$self
);
$self
->find_layout->pack_widget(
$_
,
$self
);
}
};
sub
add {
my
(
$self
,
@args
) =
@_
;
for
(
@args
) {
$_
->set_parent (
$self
);
$self
->find_layout->pack_widget(
$_
,
$self
)
if
$self
->has_gobject;
$self
->_add_content(
$_
);
}
}
sub
find {
my
(
$self
,
$name
) =
@_
;
my
@array
=
$self
->children;
while
(
my
$c
=
shift
@array
) {
return
$c
if
$c
->name eq
$name
;
push
@array
,
$c
->children
if
$c
->can(
'children'
);
}
}
sub
find_descendants {
my
(
$self
) =
@_
;
my
@descendants
;
for
my
$w
( @{
$self
->content } ) {
push
@descendants
,
$w
;
push
@descendants
,
$w
->find_descendants
if
$w
->can(
'find_descendants'
);
}
return
@descendants
;
}
1;