HTML::Widgets::NavMenu::Tree::Node - an iterator for HTML.


HTML-Widgets-NavMenu documentation Contained in the HTML-Widgets-NavMenu distribution.

Index


Code Index:

NAME

Top

HTML::Widgets::NavMenu::Tree::Node - an iterator for HTML.

SYNOPSIS

Top

For internal use only.

METHODS

Top

CurrentlyActive

Internal use.

expanded

Internal use.

CurrentlyActive

Internal use.

hide

Internal use.

host

Internal use.

role

Internal use.

rec_url_type

Internal use.

separator

Internal use.

show_always

Internal use.

skip

Internal use.

subs

Internal use.

text

Internal use.

title

Internal use.

url

Internal use.

url_is_abs

Internal use.

url_type

Internal use.

$self->expand()

Expands the node.

$self->mark_as_current()

Marks the node as the current node.

$self->update_based_on_sub

Propagate changes.

$self->add_sub()

Adds a new subroutine.

$self->get_nth_sub($idx)

Get the $idx sub.

$self->list_regular_keys()

Customisation to list the regular keys.

$self->list_boolean_keys()

Customisation to list the boolean keys.

$self->set_values_from_hash_ref($hash)

Set the values from the hash ref.

my $bool = $self->capture_expanded()

Tests whether the node is expanded and in a capturing way.

COPYRIGHT & LICENSE

Top


HTML-Widgets-NavMenu documentation Contained in the HTML-Widgets-NavMenu distribution.
package HTML::Widgets::NavMenu::Tree::Node;

use strict;
use warnings;

use base 'HTML::Widgets::NavMenu::Object';

__PACKAGE__->mk_acc_ref([
    qw(
    CurrentlyActive expanded hide host role rec_url_type
    separator show_always skip subs text title url url_is_abs url_type
    )]
    );

use HTML::Widgets::NavMenu::ExpandVal;

sub _init
{
    my $self = shift;

    $self->subs([]);

    return $self;
}

sub expand
{
    my $self = shift;
    my $v = @_ ? (shift(@_)) : 
        HTML::Widgets::NavMenu::ExpandVal->new({capture => 1})
        ;
    # Don't set it to something if it's already capture_expanded(),
    # otherwise it can set as a non-capturing expansion.
    if (! $self->capture_expanded())
    {
        $self->expanded($v);
    }
    return 0;
}

sub mark_as_current
{
    my $self = shift;
    $self->expand();
    $self->CurrentlyActive(1);
    return 0;
}

sub _process_new_sub
{
    my $self = shift;
    my $sub = shift;
    $self->update_based_on_sub($sub);    
}

sub update_based_on_sub
{
    my $self = shift;
    my $sub = shift;
    if (my $expand_val = $sub->expanded())
    {
        $self->expand($expand_val);
    }    
}

sub add_sub
{
    my $self = shift;
    my $sub = shift;
    push (@{$self->subs}, $sub);
    $self->_process_new_sub($sub);
    return 0;
}

sub get_nth_sub
{
    my $self = shift;
    my $idx = shift;
    return $self->subs()->[$idx];
}

sub _num_subs
{
    my $self = shift;
    return scalar(@{$self->subs()});
}

sub list_regular_keys
{
    my $self = shift;

    return (qw(host rec_url_type role show_always text title url url_type));
}

sub list_boolean_keys
{
    my $self = shift;

    return (qw(hide separator skip url_is_abs));
}

sub set_values_from_hash_ref
{
    my $self = shift;
    my $sub_contents = shift;

    foreach my $key ($self->list_regular_keys())
    {
        if (exists($sub_contents->{$key}))
        {
            $self->$key($sub_contents->{$key});
        }
    }

    foreach my $key ($self->list_boolean_keys())
    {
        if ($sub_contents->{$key})
        {
            $self->$key(1);
        }
    }
}

sub capture_expanded
{
    my $self = shift;

    if (my $e = $self->expanded())
    {
        return $e->is_capturing();
    }
    else
    {
        return;
    }
}

1;