line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Gimei::Parser; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
59
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
269
|
|
4
|
8
|
|
|
8
|
|
84
|
use v5.22; |
|
8
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
37
|
use App::Gimei; |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
167
|
|
7
|
8
|
|
|
8
|
|
3607
|
use Class::Tiny; |
|
8
|
|
|
|
|
22225
|
|
|
8
|
|
|
|
|
43
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub parse_args { |
10
|
28
|
|
|
28
|
0
|
73
|
my ( @args ) = @_; |
11
|
28
|
|
|
|
|
48
|
my @generators; |
12
|
|
|
|
|
|
|
|
13
|
28
|
|
|
|
|
61
|
foreach my $arg (@args) { |
14
|
29
|
|
|
|
|
99
|
push @generators, parse_arg($arg); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
25
|
|
|
|
|
837
|
return @generators; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ARG: [WORD_TYPE] [':' WORD_SUB_TYPE] [':' RENDERING] |
21
|
|
|
|
|
|
|
# WORD_TYPE: 'name' | 'male' | 'female' | 'address' |
22
|
|
|
|
|
|
|
# WORD_SUBTYPE(name|male|female): 'family' | 'given' |
23
|
|
|
|
|
|
|
# WORD_SUBTYPE(address): 'prefecture' | 'city' | 'town' |
24
|
|
|
|
|
|
|
# RENDERING: 'kanji' | 'hiragana' | 'katakana' | 'romaji' |
25
|
|
|
|
|
|
|
sub parse_arg { |
26
|
29
|
|
|
29
|
0
|
68
|
my ( $arg ) = @_; |
27
|
29
|
|
|
|
|
55
|
my ( $gen, @tokens, %params ); |
28
|
|
|
|
|
|
|
|
29
|
29
|
|
|
|
|
119
|
@tokens = split( /[-:]/, $arg ); |
30
|
|
|
|
|
|
|
|
31
|
29
|
|
|
|
|
70
|
my $token = shift @tokens; |
32
|
29
|
100
|
100
|
|
|
226
|
if ( $token eq 'name' || $token eq 'male' || $token eq 'female' ) { |
|
|
100
|
100
|
|
|
|
|
33
|
18
|
|
|
|
|
60
|
$params{word_class} = "Data::Gimei::Name"; |
34
|
18
|
100
|
|
|
|
83
|
if ($token ne 'name') { |
35
|
5
|
|
|
|
|
14
|
$params{gender} = $token; |
36
|
|
|
|
|
|
|
} |
37
|
18
|
|
|
|
|
70
|
$params{word_subtype} = subtype_name( \@tokens ); |
38
|
|
|
|
|
|
|
} elsif ( $token eq 'address' ) { |
39
|
10
|
|
|
|
|
28
|
$params{word_class} = "Data::Gimei::Address"; |
40
|
10
|
|
|
|
|
34
|
$params{word_subtype} = subtype_address( \@tokens ); |
41
|
|
|
|
|
|
|
} else { |
42
|
1
|
|
|
|
|
15
|
die "Error: unknown word_type: $token\n"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
28
|
|
|
|
|
84
|
my ( $ok, $render ) = render( \@tokens ); |
46
|
28
|
100
|
|
|
|
83
|
if ( ! $ok ) { |
47
|
2
|
50
|
|
|
|
6
|
if ( defined $params{word_subtype} ) { |
48
|
0
|
|
|
|
|
0
|
die "Error: unknown rendering: $render\n"; |
49
|
|
|
|
|
|
|
} else { |
50
|
2
|
|
|
|
|
20
|
die "Error: unknown subtype or rendering: $render\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
26
|
|
|
|
|
54
|
$params{render} = $render; |
54
|
|
|
|
|
|
|
|
55
|
26
|
|
|
|
|
197
|
return App::Gimei::Generator->new( %params ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub subtype_name { |
59
|
18
|
|
|
18
|
0
|
41
|
my ( $tokens_ref ) = @_; |
60
|
18
|
|
|
|
|
34
|
my ( $word_subtype ); |
61
|
|
|
|
|
|
|
|
62
|
18
|
|
|
|
|
126
|
my %map = ( |
63
|
|
|
|
|
|
|
'family' => 'surname', |
64
|
|
|
|
|
|
|
'last' => 'surname', |
65
|
|
|
|
|
|
|
'given' => 'forename', |
66
|
|
|
|
|
|
|
'first' => 'forename', |
67
|
|
|
|
|
|
|
'gender' => 'gender', |
68
|
|
|
|
|
|
|
'sex' => 'gender', |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
18
|
|
100
|
|
|
95
|
my $token = @$tokens_ref[0] // ''; |
72
|
18
|
100
|
|
|
|
60
|
if ( $word_subtype = $map{$token} ) { |
73
|
9
|
|
|
|
|
17
|
shift @$tokens_ref; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
18
|
|
|
|
|
68
|
return $word_subtype; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub subtype_address { |
80
|
10
|
|
|
10
|
0
|
23
|
my ( $tokens_ref ) = @_; |
81
|
10
|
|
|
|
|
19
|
my ( $word_subtype ); |
82
|
|
|
|
|
|
|
|
83
|
10
|
|
100
|
|
|
43
|
my $token = @$tokens_ref[0] // ''; |
84
|
10
|
100
|
100
|
|
|
74
|
if ( $token eq 'prefecture' || $token eq 'city' || $token eq 'town' ) { |
|
|
|
100
|
|
|
|
|
85
|
6
|
|
|
|
|
13
|
shift @$tokens_ref; |
86
|
6
|
|
|
|
|
13
|
$word_subtype = $token; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
10
|
|
|
|
|
49
|
return $word_subtype; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# romaji not supported in WORD_TYPE = 'address' |
93
|
|
|
|
|
|
|
sub render { |
94
|
28
|
|
|
28
|
0
|
65
|
my ( $tokens_ref ) = @_; |
95
|
28
|
|
|
|
|
49
|
my $status = ''; |
96
|
|
|
|
|
|
|
|
97
|
28
|
|
|
|
|
51
|
my $token = @$tokens_ref[0]; |
98
|
28
|
100
|
100
|
|
|
168
|
if ( !defined $token || |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
99
|
|
|
|
|
|
|
$token eq 'kanji' || $token eq 'hiragana' || |
100
|
|
|
|
|
|
|
$token eq 'katakana' || $token eq 'romaji' ) { |
101
|
26
|
|
|
|
|
53
|
$status = 'ok'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
28
|
|
|
|
|
79
|
return ( $status, $token ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |