File Coverage

blib/lib/Lingua/DE/Num2Word.pm
Criterion Covered Total %
statement 13 42 30.9
branch 0 28 0.0
condition 0 18 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 18 94 19.1


line stmt bran cond sub pod time code
1             # For Emacs: -*- mode:cperl; mode:folding; coding:iso-8859-1 -*-
2             #
3             # (c) 2002-2004 PetaMem, s.r.o.
4             #
5             # PPCG: 0.7
6              
7             package Lingua::DE::Num2Word;
8              
9 1     1   9958 use strict;
  1         3  
  1         46  
10              
11             # {{{ BEGIN
12             #
13             BEGIN {
14 1     1   6 use Exporter ();
  1         1  
  1         21  
15 1     1   5 use vars qw($VERSION $REVISION @ISA @EXPORT_OK);
  1         7  
  1         164  
16 1     1   2 $VERSION = '0.03';
17 1         5 ($REVISION) = '$Revision: 1.10 $' =~ /([\d.]+)/;
18 1         14 @ISA = qw(Exporter);
19 1         786 @EXPORT_OK = qw(&num2de_cardinal);
20             }
21             # }}}
22              
23             # {{{ num2de_cardinal convert number to text
24             #
25             sub num2de_cardinal {
26 0     0 1   my $positive = shift;
27              
28 0           my @tokens1 = qw(null ein zwei drei vier fünf sechs sieben acht neun zehn elf zwölf);
29 0           my @tokens2 = qw(zwanzig dreissig vierzig fünfzig sechzig siebzig achtzig neunzig hundert);
30              
31 0 0 0       return $tokens1[$positive] if($positive >= 0 && $positive < 13); # 0 .. 12
32 0 0         return 'sechzehn' if($positive == 16); # 16 exception
33 0 0         return 'siebzehn' if($positive == 17); # 17 exception
34 0 0 0       return $tokens1[$positive-10].'zehn' if($positive > 12 && $positive < 20); # 13 .. 19
35              
36 0           my $out; # string for return value construction
37             my $one_idx; # index for tokens1 array
38 0           my $remain; # remainder
39              
40 0 0 0       if($positive > 19 && $positive < 101) { # 20 .. 100
    0 0        
    0 0        
    0 0        
41 0           $one_idx = int ($positive / 10);
42 0           $remain = $positive % 10;
43              
44 0 0         $out = "$tokens1[$remain]und" if $remain;
45 0           $out .= $tokens2[$one_idx-2];
46              
47             } elsif($positive > 100 && $positive < 1000) { # 101 .. 999
48 0           $one_idx = int ($positive / 100);
49 0           $remain = $positive % 100;
50              
51 0           $out = "$tokens1[$one_idx]hundert";
52 0 0         $out .= $remain ? &num2de_cardinal($remain) : '';
53              
54             } elsif($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999
55 0           $one_idx = int ($positive / 1000);
56 0           $remain = $positive % 1000;
57              
58 0           $out = &num2de_cardinal($one_idx).'tausend';
59 0 0         $out .= $remain ? &num2de_cardinal($remain) : '';
60              
61             } elsif($positive > 999_999 &&
62             $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999
63 0           $one_idx = int ($positive / 1000000);
64 0           $remain = $positive % 1000000;
65 0 0         my $one = $one_idx == 1 ? 'e' : '';
66              
67 0           $out = &num2de_cardinal($one_idx)."$one million";
68 0 0         $out .= 'en' if $one_idx > 1;
69 0 0         $out .= $remain ? ' '.&num2de_cardinal($remain) : '';
70             }
71              
72 0           return $out;
73             }
74              
75             # }}}
76              
77             1;
78             __END__