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   46448 use warnings;
  2         4  
  2         65  
4 2     2   10 use strict;
  2         3  
  2         74  
5 2     2   11 use vars qw($VERSION);
  2         7  
  2         107  
6             $VERSION = '0.10';
7              
8 2     2   18 use File::Spec;
  2         2  
  2         69  
9 2     2   2035 use Lingua::Han::Utils qw/Unihan_value/;
  2         176159  
  2         676  
10              
11             sub new {
12 1     1 0 55 my $class = shift;
13 1         3 my $dir = __FILE__; $dir =~ s/\.pm//o;
  1         9  
14 1 50       71 -d $dir or die "Directory $dir nonexistent!";
15 1         3 my $self;
16             my %st;
17 1         37 my $file = File::Spec->catfile($dir, 'Stroke.dat');
18 1 50       77 open(FH, $file) or die "$file: $!";
19 1         46 while() {
20 74911         163616 my ($uni, $st) = split(/\s+/);
21 74911         309449 $st{$uni} = $st;
22             }
23 1         53 close(FH);
24 1         9 $self->{'st'} = \%st;
25 1         16 return bless $self => $class;
26             }
27              
28             sub stroke {
29 1     1 0 12 my ($self, $hanzi) = @_;
30 1         7 my $code = Unihan_value($hanzi); # got the Unihan field 1
31 1         275 return $self->{'st'}->{$code};
32             }
33             1;
34             __END__