File Coverage

blib/lib/Lingua/Han/Stroke.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 40 44 90.9


line stmt bran cond sub pod time code
1             package Lingua::Han::Stroke;
2              
3 2     2   38127 use warnings;
  2         9  
  2         89  
4 2     2   15 use strict;
  2         8  
  2         68  
5 2     2   13 use vars qw($VERSION);
  2         12  
  2         164  
6             $VERSION = '0.11';
7              
8 2     2   16 use File::Spec;
  2         4  
  2         56  
9 2     2   998 use Lingua::Han::Utils qw/Unihan_value/;
  2         147797  
  2         577  
10              
11             sub new {
12 1     1 0 16 my $class = shift;
13 1         3 my $dir = __FILE__; $dir =~ s/\.pm//o;
  1         8  
14 1 50       39 -d $dir or die "Directory $dir nonexistent!";
15 1         4 my $self;
16             my %st;
17 1         28 my $file = File::Spec->catfile($dir, 'Stroke.dat');
18 1 50       36 open(FH, $file) or die "$file: $!";
19 1         34 while() {
20 80682         264457 my ($uni, $st) = split(/\s+/);
21 80682         329898 $st{$uni} = $st;
22             }
23 1         24 close(FH);
24 1         7 $self->{'st'} = \%st;
25 1         12 return bless $self => $class;
26             }
27              
28             sub stroke {
29 1     1 0 14 my ($self, $hanzi) = @_;
30 1         10 my $code = Unihan_value($hanzi); # got the Unihan field 1
31 1         330 return $self->{'st'}->{$code};
32             }
33             1;
34             __END__