package Text::Wigwam::Engine::Totem::Token::Literal;

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

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

    use Text::Wigwam::Engine::Totem::Const( qw/PTXT/ );
    use Text::Wigwam::Const( qw/RUNONCE/ );

sub new {
    my ($class, $data, $htyp, $draw, $type) = @_;
    return bless {
        DATA => [ $data, $htyp ],
        DRAW => $draw,
        TYPE => $type,
    }, $class;
}

sub exec {
    my ($tokn, $want, $Arg, $Api, $core) = @_;
    $core->next_token;
    return $Arg->null_data($want)
      if ($want & RUNONCE) && $tokn->{ONCE}++;
    return
        exists $tokn->{CACHE}
        ? $tokn->{CACHE}
        : $tokn->{CACHE} = $tokn->cast( $Arg, $Api, $want, @{$tokn->{DATA}} )
    ;
}
sub skip {
     # my (undef, undef, undef, $Api, $core) = @_;
    $_[4]->next_token;
    return;
}
sub paint {
    my ($tokn, undef, $Api, $core) = @_;
    $core->next_token;
    return(
        Text::Wigwam::Engine::Totem::Paint::Group->new(
            [ @{$tokn->{PAINT} ||= $tokn->_paint($Api, $core)} ]
        ),
        0,
    );
}
sub _paint {
    my ($self, $Api, $core) = @_;
    my $paint = [];
    if( $self->{TYPE} & PTXT ){
        push(
            @$paint,
            Text::Wigwam::Engine::Totem::Paint::Token->new(
                $self->{DRAW}[0],
                $core->curr_addr,
                'plaintext'
            )
        );
    }
    else{
        push(
            @$paint,
            Text::Wigwam::Engine::Totem::Paint::Token->new(
                $self->{DRAW}[0],
                $core->curr_addr,
                'literal'
            )
        )
    }
    return $paint;
}

1;
