
package Text::Wigwam::Engine::Totem::Token::Terminator::Root;

    use strict;
    use warnings;
    our $VERSION = '0.01';

    use base q/Text::Wigwam::Cast/;

    use Text::Wigwam::Engine::Totem::Const(
      qw/
        TEXT_BLOCK
        ROOT_BLOCK
        CODE_BLOCK
      /
    );
    use Text::Wigwam::Const qw/ TERM /;

sub new { return bless { DRAW => $_[1] } }
sub exec {
    my ($tokn, $want, $Arg, $Api, $core) = @_;
    $Arg->end_list(1); # Always set the list terminator flag
    $Api->exception(
      "Unexpectedly encountered the end of the template"
    ) if !($Arg->type & ROOT_BLOCK) && $Api->get_options(qw/strict_tags/);
    return;
}
sub skip {
    my ($tokn, $list, $Arg, $Api, $core) = @_;
     # Strict template code enforcement feature
    $Api->exception(
      "Unexpectedly encountered the end of the template"
    ) if !($Arg->type & ROOT_BLOCK) && $Api->get_options(qw/strict_tags/);
    return TERM; # Always signal the end of list
}

sub paint {
    my ($tokn, $Arg, $Api, $core) = @_;
    my $color;
    if ( $Arg->type & ROOT_BLOCK ){
      $color = Text::Wigwam::Engine::Totem::Paint::Group->new(
        [
          Text::Wigwam::Engine::Totem::Paint::Token->new(
            $tokn->{DRAW}[0],
            $core->curr_addr,
            'tagentity',
          ),
        ],
      );
    }
    else {
       # Terminate the non-ROOT_BLOCK list.
      $color = Text::Wigwam::Engine::Totem::Paint::Group->new(
        [
         Text::Wigwam::Engine::Totem::Paint::Token->new(
          (
              $Arg->mate
           || (
                ($Arg->type & TEXT_BLOCK)
                 ? $Api->get_options(qw/text_term/) || "<!!"
                 : ($Arg->type == CODE_BLOCK)
                   ? $Api->get_options(qw/code_term/) || "!!]"
                   : '#/*'
              )
          ),
          $core->curr_addr,
          'implied',
         ),
        ],
      );
    }
    return( $color, 1 );
}

1;
