Hailo::Tokenizer::Chars - A character tokenizer for L<Hailo|Hailo>


Hailo documentation Contained in the Hailo distribution.

Index


Code Index:

NAME

Top

Hailo::Tokenizer::Chars - A character tokenizer for Hailo

DESCRIPTION

Top

This tokenizer dumbly splits input with split //. Use it to generate chains on a per-character basis.

AUTHOR

Top

Ævar Arnfjörð Bjarmason <avar@cpan.org>

LICENSE AND COPYRIGHT

Top


Hailo documentation Contained in the Hailo distribution.

package Hailo::Tokenizer::Chars;
BEGIN {
  $Hailo::Tokenizer::Chars::AUTHORITY = 'cpan:AVAR';
}
BEGIN {
  $Hailo::Tokenizer::Chars::VERSION = '0.69';
}

use 5.010;
use Any::Moose;
use Any::Moose 'X::StrictConstructor';
use namespace::clean -except => 'meta';

with qw(Hailo::Role::Arguments
        Hailo::Role::Tokenizer);

# output -> tokens
sub make_tokens {
    my ($self, $line) = @_;
    my @chars = split //, $line;
    my @tokens = map { [$self->{_spacing_normal}, $_] } @chars;
    return \@tokens;
}

# tokens -> output
sub make_output {
    my ($self, $tokens) = @_;
    return trim(join '', map { $_->[1] } @$tokens);
}

sub trim {
    my $txt = shift;
    $txt =~ s/^\s+//;
    $txt =~ s/\s+$//;
    return $txt;
}

__PACKAGE__->meta->make_immutable;