Tree-Navigator
view release on metacpan or search on metacpan
lib/Tree/Navigator/Node.pm view on Meta::CPAN
#======================================================================
# generic methods
#======================================================================
sub descendent {
my ($self, $path) = @_;
# $self is its own descendent if $path is empty
return $self if ($path // '') eq ''; # NOTE : '0' is a valid nonempty path!
# otherwise, find the child from initial path segment, and then recurse
my ($child_name, $subpath) = split m{/}, $path, 2;
my $child = $self->child($child_name)
or die "no such child: $child_name";
return $child->descendent($subpath);
}
sub is_parent { # default implementation; may be optimised in subclasses
my $self = shift;
my @children = $self->children;
return @children ? 1 : 0;
}
lib/Tree/Navigator/Node/Perl/Ref.pm view on Meta::CPAN
exclude => {type => SCALARREF, isa => 'Regexp', optional => 1},
});
}
sub _find_ref {
my $self = shift;
my $path = $self->path || "" ;
my $ref = $self->mount_point->{ref};
foreach my $fragment (split m[/], $path) {
my $reftype = reftype $ref;
if ($reftype eq 'ARRAY') {
$ref = $ref->[$fragment];
}
elsif ($reftype eq 'HASH') {
$ref = $ref->{$fragment};
}
elsif ($reftype eq 'SCALAR' || $reftype eq 'REF') {
$ref = $$ref;
}
( run in 0.713 second using v1.01-cache-2.11-cpan-5511b514fd6 )