| 1 | package Lingua::ZH::ZhuYin::Dict; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | Lingua::ZH::ZhuYin::Dict - The backend dictionary for converting zhuyin | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 VERSION | ||||||||||||
| 11 | |||||||||||||
| 12 | Version 0.03 | ||||||||||||
| 13 | |||||||||||||
| 14 | =cut | ||||||||||||
| 15 | |||||||||||||
| 16 | 3 | our $VERSION = 0.03; | |||||||||||
| 17 | 3 | ▶ | use DBI qw(:sql_types); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 3 | ▶ | use DBD::SQLite; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||
| 21 | |||||||||||||
| 22 | Quick summary of what the module does. | ||||||||||||
| 23 | |||||||||||||
| 24 | Perhaps a little code snippet. | ||||||||||||
| 25 | |||||||||||||
| 26 | use Lingua::ZH::ZhuYin::Dict; | ||||||||||||
| 27 | |||||||||||||
| 28 | my $zhuyin = Lingua::ZH::ZhuYin::Dict::QueryZuyin($word); | ||||||||||||
| 29 | ... | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 EXPORT | ||||||||||||
| 32 | |||||||||||||
| 33 | A list of functions that can be exported. You can delete this section | ||||||||||||
| 34 | if you don't export anything, such as for a purely object-oriented module. | ||||||||||||
| 35 | |||||||||||||
| 36 | =head1 FUNCTIONS | ||||||||||||
| 37 | |||||||||||||
| 38 | =head2 new | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | 2 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||
| 43 | 2 | my $class = shift; | |||||||||||
| 44 | 2 | my $self = { | |||||||||||
| 45 | table => undef, | ||||||||||||
| 46 | dbh => undef, | ||||||||||||
| 47 | }; | ||||||||||||
| 48 | 2 | ▶ | my $dictFile = shift || 'moedict.db'; | ||||||||||
|
Condition50%1/2
shift() || 'moedict.db'
MC/DC0%0/1
shift() || 'moedict.db'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 49 | 2 | ▶ | if ( -f $dictFile ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 50 | 2 | my $dsn = "dbi:SQLite:dbname=$dictFile"; | |||||||||||
| 51 | 2 | $self->{dbh} = DBI->connect($dsn, "",""); | |||||||||||
| 52 | } | ||||||||||||
| 53 | 2 | ($self->{table}) = ($dictFile =~ /(\w+)\.db/); | |||||||||||
| 54 | 2 | ▶ | $self->{table} ||= 'moedict'; | ||||||||||
|
Condition50%1/2
$self->{"table"} ||= "moedict"
MC/DC0%0/1
$self->{"table"} ||= "moedict"
$self->{"table"}
Truth table50%1/2
A
A= $self->{"table"}
| |||||||||||||
| 55 | 2 | bless ($self, $class); | |||||||||||
| 56 | 2 | return($self); | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 queryZhuYin | ||||||||||||
| 60 | |||||||||||||
| 61 | =cut | ||||||||||||
| 62 | |||||||||||||
| 63 | 2 | ▶ | sub queryZhuYin { | ||||||||||
|
Subroutine
queryZhuYin: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 64 | 2 | my $self = shift; | |||||||||||
| 65 | 2 | my $word = shift; | |||||||||||
| 66 | |||||||||||||
| 67 | 2 | ▶ | return unless $self->{dbh}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | 2 | my @zhuyins; | |||||||||||
| 70 | 2 | my $table = $self->{table}; | |||||||||||
| 71 | 2 | my $sth = $self->{dbh}->prepare("SELECT zhuyin from $table WHERE word = ?"); | |||||||||||
| 72 | 2 | ▶ | $sth->execute($word) || die DBI::err.": ".$DBI::errstr; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | 2 | ▶ | while (my $hash_ref = $sth->fetchrow_hashref) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 2 | push @zhuyins, $hash_ref->{zhuyin}; | |||||||||||
| 75 | } | ||||||||||||
| 76 | 2 | return @zhuyins; | |||||||||||
| 77 | } | ||||||||||||
| 78 | |||||||||||||
| 79 | =head1 AUTHOR | ||||||||||||
| 80 | |||||||||||||
| 81 | Cheng-Lung Sung, C<< <clsung at cpan.org> >> | ||||||||||||
| 82 | |||||||||||||
| 83 | =head1 ACKNOWLEDGEMENTS | ||||||||||||
| 84 | |||||||||||||
| 85 | |||||||||||||
| 86 | =head1 COPYRIGHT & LICENSE | ||||||||||||
| 87 | |||||||||||||
| 88 | Copyright 2008 Cheng-Lung Sung, all rights reserved. | ||||||||||||
| 89 | |||||||||||||
| 90 | This program is free software; you can redistribute it and/or modify it | ||||||||||||
| 91 | under the same terms as Perl itself. | ||||||||||||
| 92 | |||||||||||||
| 93 | |||||||||||||
| 94 | =cut | ||||||||||||
| 95 | |||||||||||||
| 96 | 3 | 1; # End of Lingua::ZH::ZhuYin::Dict | |||||||||||