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

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

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

    use Text::Wigwam::Const( qw/VAR RUNONCE/ );

sub new {
    my ($class, $data, $draw ) = @_;
    return bless {
        DATA => [ VAR, $data ],
        DRAW => $draw,
        ONCE => 0,
    }, ref($class) || $class;
}

sub exec {
    my ($tokn, $want, $Arg, $Api, $core) = @_;
    $core->next_token;
    return $Arg->null_data($want)
      if ($want & RUNONCE) && $tokn->{ONCE}++;
    return $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 = [];
    push(
        @$paint,
        Text::Wigwam::Engine::Totem::Paint::Token->new(
            $self->{DRAW}[0],
            $core->curr_addr,
            'variable',
        )
    );
    return $paint;
}

1;
