| Lingua-ZH-ZhuYin documentation | Contained in the Lingua-ZH-ZhuYin distribution. |
Lingua::ZH::ZhuYin::Dict - The backend dictionary for converting zhuyin
Version 0.03
Quick summary of what the module does.
Perhaps a little code snippet.
use Lingua::ZH::ZhuYin::Dict;
my $zhuyin = Lingua::ZH::ZhuYin::Dict::QueryZuyin($word);
...
A list of functions that can be exported. You can delete this section if you don't export anything, such as for a purely object-oriented module.
Cheng-Lung Sung, <clsung at cpan.org>
Copyright 2008 Cheng-Lung Sung, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Lingua-ZH-ZhuYin documentation | Contained in the Lingua-ZH-ZhuYin distribution. |
package Lingua::ZH::ZhuYin::Dict; use warnings; use strict;
our $VERSION = 0.03; use DBI qw(:sql_types); use DBD::SQLite;
sub new { my $class = shift; my $self = { table => undef, dbh => undef, }; my $dictFile = shift || 'moedict.db'; if ( -f $dictFile ) { my $dsn = "dbi:SQLite:dbname=$dictFile"; $self->{dbh} = DBI->connect($dsn, "",""); } ($self->{table}) = ($dictFile =~ /(\w+)\.db/); $self->{table} ||= 'moedict'; bless ($self, $class); return($self); }
sub queryZhuYin { my $self = shift; my $word = shift; return unless $self->{dbh}; my @zhuyins; my $table = $self->{table}; my $sth = $self->{dbh}->prepare("SELECT zhuyin from $table WHERE word = ?"); $sth->execute($word) || die DBI::err.": ".$DBI::errstr; while (my $hash_ref = $sth->fetchrow_hashref) { push @zhuyins, $hash_ref->{zhuyin}; } return @zhuyins; }
1; # End of Lingua::ZH::ZhuYin::Dict