HTML::Widgets::NavMenu::Iterator::Base - base class for the iterator.


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

Index


Code Index:

NAME

Top

HTML::Widgets::NavMenu::Iterator::Base - base class for the iterator.

SYNOPSIS

Top

For internal use only.

METHODS

Top

$self->get_initial_node()

Gets the initial node.

$self->get_node_subs({ node => $node})

Gets the subs of the node.

$self->get_new_accum_state( { item => $item, node => $node } )

Gets the new accumulated state.

my $array_ref = $self->get_results()

Returns an array reference with the resultant HTML.

COPYRIGHT & LICENSE

Top


HTML-Widgets-NavMenu documentation Contained in the HTML-Widgets-NavMenu distribution.
package HTML::Widgets::NavMenu::Iterator::Base;

use strict;
use warnings;

use base qw(HTML::Widgets::NavMenu::Tree::Iterator);

__PACKAGE__->mk_acc_ref([qw(
    _html
    nav_menu
    )]);

sub _init
{
    my $self = shift;
    my $args = shift;

    $self->SUPER::_init($args);

    $self->nav_menu($args->{'nav_menu'}) or
        die "nav_menu not specified!";

    $self->_html([]);

    return 0;
}

sub _add_tags
{
    my $self = shift;
    push (@{$self->_html()}, @_);
}

sub _is_root
{
    my $self = shift;

    return ($self->stack->len() == 1);
}

sub _is_top_separator
{
    my $self = shift;

    return $self->top->_node->separator;
}

sub get_initial_node
{
    my $self = shift;
    return $self->nav_menu->_get_traversed_tree();
}


sub get_node_subs
{
    my ($self, $args) = @_;

    my $node = $args->{'node'};

    return [ @{$node->subs()} ];
}

# TODO : This method is too long - refactor.
sub get_new_accum_state
{
    my ($self, $args) = @_;

    my $parent_item = $args->{'item'};
    my $node = $args->{'node'};
    
    my $prev_state;
    if (defined($parent_item))
    {
        $prev_state = $parent_item->_accum_state();
    }
    else
    {
        $prev_state = +{};
    }

    my $show_always = 0;
    if (exists($prev_state->{'show_always'}))
    {
        $show_always = $prev_state->{'show_always'};
    }
    if (defined($node->show_always()))
    {
        $show_always = $node->show_always();
    }
    
    my $rec_url_type;
    if (exists($prev_state->{'rec_url_type'}))
    {
        $rec_url_type = $prev_state->{'rec_url_type'};
    }
    if (defined($node->rec_url_type()))
    {
        $rec_url_type = $node->rec_url_type();
    }
    return
        {
            'host' => ($node->host() ? $node->host() : $prev_state->{'host'}),
            'show_always' => $show_always,
            'rec_url_type' => $rec_url_type,
        };
}

sub get_results
{
    my $self = shift;

    return [ @{$self->_html()} ];
}

1;