CPAN-Flatten
view release on metacpan or search on metacpan
lib/CPAN/Flatten/Tree.pm view on Meta::CPAN
123456789101112131415161718192021222324252627282930313233343536package
CPAN::Flatten::Tree;
use
strict;
use
warnings;
use
utf8;
sub
new {
my
$class
=
shift
;
my
%args
=
ref
$_
[0] ? %{
$_
[0]} :
@_
;
my
$self
=
bless
{
_parent
=>
undef
,
_children
=> [],
%args
,
},
$class
;
$self
;
}
sub
add_child {
my
(
$self
,
$node
) =
@_
;
if
(
$node
->{_parent}) {
Carp::confess(
"node (@{[$node->uid]}) already has a parent"
);
}
push
@{
$self
->{_children} },
$node
;
$node
->{_parent} =
$self
;
weaken
$node
->{_parent};
$self
;
}
sub
is_child {
my
(
$self
,
$that
) =
@_
;
for
my
$child
(
$self
->children) {
return
1
if
$child
->equals(
$that
);
}
return
;
}
( run in 0.303 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )