| 1 | 8 | ▶ | use v5.42; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use feature 'class'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | no warnings 'experimental::class'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | class App::Gimei::Parser { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use App::Gimei::Generator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use App::Gimei::Generators; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # private instance methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 36 | ▶ | my method _subtype_name ($tokens_ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subtype_name: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 36 | my $word_subtype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 36 | my %map = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'family' => 'surname', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'last' => 'surname', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'given' => 'forename', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'first' => 'forename', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'gender' => 'gender', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'sex' => 'gender', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 36 | ▶ | my $token = @$tokens_ref[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
@$tokens_ref[0] // ""
MC/DC100%1/1
@$tokens_ref[0] // ""
@$tokens_ref[0]
Truth table100%2/2
A
A= @$tokens_ref[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 36 | ▶ | if ( $word_subtype = $map{$token} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 16 | shift @$tokens_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 36 | return $word_subtype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | my method _subtype_address ($tokens_ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_subtype_address: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | my ($word_subtype); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | ▶ | my $token = @$tokens_ref[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
@$tokens_ref[0] // ""
MC/DC100%1/1
@$tokens_ref[0] // ""
@$tokens_ref[0]
Truth table100%2/2
A
A= @$tokens_ref[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 16 | ▶ | if ( $token eq 'prefecture' || $token eq 'city' || $token eq 'town' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$token eq "prefecture" or $token eq "city" or $token eq "town"
$token eq "prefecture" or $token eq "city"
MC/DC100%3/3
$token eq "prefecture" or $token eq "city" or $token eq "town"
$token eq "prefecture"
$token eq "city"
$token eq "town"
Truth table100%4/4
A or B or C
A= $token eq "prefecture"B= $token eq "city"C= $token eq "town"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | shift @$tokens_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | $word_subtype = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 16 | return $word_subtype; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 52 | ▶ | my method _rendering ($tokens_ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rendering: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 52 | my $rendering = 'kanji'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 52 | ▶ | my $token = @$tokens_ref[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
@$tokens_ref[0] // ""
MC/DC100%1/1
@$tokens_ref[0] // ""
@$tokens_ref[0]
Truth table100%2/2
A
A= @$tokens_ref[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 52 | ▶ | if ( $token eq 'kanji' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$token eq "kanji" or $token eq "hiragana" or $token eq "katakana" or $token eq "romaji"
$token eq "kanji" or $token eq "hiragana" or $token eq "katakana"
$token eq "kanji" or $token eq "hiragana"
MC/DC100%4/4
$token eq "kanji" or $token eq "hiragana" or $token eq "katakana" or $token eq "romaji"
$token eq "kanji"
$token eq "hiragana"
$token eq "katakana"
$token eq "romaji"
Truth table100%5/5
A or B or C or D
A= $token eq "kanji"B= $token eq "hiragana"C= $token eq "katakana"D= $token eq "romaji"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | || $token eq 'hiragana' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | || $token eq 'katakana' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | || $token eq 'romaji' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 14 | shift @$tokens_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 14 | $rendering = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 52 | return $rendering; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # BNF-like notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # ARG: [WORD_TYPE] [':' RENDERING] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # WORD_TYPE: TYPE_NAME [':' SUBTYPE_NAME] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # | TYPE_ADDRESS [':' SUBTYPE_ADDRESS] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # TYPE_NAME: 'name' | 'male' | 'female' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # SUBTYPE_NAME: 'family' | 'given' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # TYPE_ADDRESS: 'address' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # SUBTYPE_ADDRESS: 'prefecture' | 'city' | 'town' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # RENDERING: 'kanji' | 'hiragana' | 'katakana' | 'romaji' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # (DO NOT support romaji rendering for type address) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 54 | ▶ | my method _parse_arg ($arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_arg: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 54 | my ( $gen, @tokens, %params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 54 | @tokens = split( /[-:]/, $arg ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 54 | my $token = shift @tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 54 | ▶ | if ( $token eq 'name' || $token eq 'male' || $token eq 'female' ) { # TYPE_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$token eq "name" or $token eq "male" or $token eq "female"
$token eq "name" or $token eq "male"
MC/DC100%3/3
$token eq "name" or $token eq "male" or $token eq "female"
$token eq "name"
$token eq "male"
$token eq "female"
Truth table100%4/4
A or B or C
A= $token eq "name"B= $token eq "male"C= $token eq "female"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 36 | $params{word_class} = "Data::Gimei::Name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 36 | ▶ | if ( $token ne 'name' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | $params{gender} = $token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 36 | $params{word_subtype} = $self->&_subtype_name( \@tokens ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif ( $token eq 'address' ) { # TYPE_ADDRESS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | $params{word_class} = "Data::Gimei::Address"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 16 | $params{word_subtype} = $self->&_subtype_address( \@tokens ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | die "Error: unknown word_type: $token\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 52 | $params{rendering} = $self->&_rendering( \@tokens ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 52 | ▶ | if (@tokens) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | ▶ | if ( defined $params{word_subtype} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | die "Error: unknown rendering: $tokens[0]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | die "Error: unknown subtype or rendering: $tokens[0]\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 48 | return App::Gimei::Generator->new(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # public class methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 37 | ▶ | sub parse ($aref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 37 | my $p = App::Gimei::Parser->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 37 | my $generators = App::Gimei::Generators->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 37 | foreach my $arg ( @{$aref} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 54 | $generators->add_generator( $p->&_parse_arg($arg) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 31 | return $generators; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||