Acme-AjiFry

 view release on metacpan or  search on metacpan

lib/Acme/AjiFry/EN.pm  view on Meta::CPAN

sub translate_from_ajifry {
    my ( $self, $ajifry_word ) = @_;
    return $self->to_English($ajifry_word);
}

sub _to_ajifry {
    my $self       = shift;
    my $raw_string = shift;

    my @raw_chars = split //, $raw_string;
    my $ajifry_word;
    foreach my $raw_char (@raw_chars) {
        if ( $raw_char eq ' ' ) {
            $ajifry_word .= MAP->{space};
        }
        elsif ( $raw_char =~ /[a-zA-Z0-9]/ ) {
            $ajifry_word .= MAP->{$raw_char};
        }
        else {
            $ajifry_word .= $raw_char;
        }
    }

    return $ajifry_word;
}

sub _to_English {
    my $self        = shift;
    my $ajifry_word = shift;

    my $translated_word;
    while ($ajifry_word) {
        my $match = 0;

        my $map = MAP;
        foreach my $key ( keys %{$map} ) {
            if ( $ajifry_word =~ s/^$map->{$key}// ) {
                $match = 1;
                if ( $key eq 'space' ) {
                    $translated_word .= ' ';
                }
                else {
                    $translated_word .= $key;
                }
                last;
            }
        }

        unless ($match) {
            $ajifry_word =~ s/^(.)//;
            $translated_word .= $1;
        }
    }

    return $translated_word;
}
1;

__END__

=encoding utf8

=head1 NAME

Acme::AjiFry::EN - AjiFry Language Translator for English


=head1 SYNOPSIS

    use Acme::AjiFry::EN;

    my $ajifry_en = Acme::AjiFry::EN->new();

    print $ajifry_en->to_AjiFry('012abcABC!!!')."\n"; # outputs => '京極お刺身京極むむ・・・京極アジフライ食え食え食え食えドボドボ食えお刺身山岡ドボドボ山岡お刺身山岡むむ・・・!!!'
    print $ajifry_en->to_English('京極お刺身京極むむ・・・京極アジフライ食え食え食え食えドボドボ食えお刺身山岡ドボドボ山岡お刺身山岡むむ・・・!!!')."\n"; # outputs => '012abcABC!!!'


=head1 DESCRIPTION

Acme::AjiFry::EN is the AjiFry-Language translator.
This module can translate English into AjiFry-Language, and vice versa.


=head1 SEE ALSO

L<Acme::AjiFry>.


=head1 METHODS

=over

=item new

new is the constructor of this module.

=item to_English

This function needs a AjiFry-Language string as parameter.
It returns English which was translated from AjiFry-Language.

=item to_AjiFry

This function needs a string as parameter.
It returns AjiFry-Language which was translated from English.

=back


=head1 AUTHOR

moznion  C<< <moznion[at]gmail.com> >>


=head1 LICENCE AND COPYRIGHT

Copyright (c) 2012, moznion C<< <moznion[at]gmail.com> >>. All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.



( run in 0.991 second using v1.01-cache-2.11-cpan-f56aa216473 )