| 1 | package Lingua::Sindarin::Dictionary; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use v5.12; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 1 | our $VERSION = '0.01'; | |||||||||||||
| 11 | |||||||||||||||
| 12 | 1 | has 'dictionary' => ( | |||||||||||||
| 13 | is => 'rw', | ||||||||||||||
| 14 | isa => 'ArrayRef', | ||||||||||||||
| 15 | ); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | ▶ | sub BUILD { | ||||||||||||
|
Subroutine
BUILD: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||
| 19 | 0 | my $opt = shift; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | my %opt = %{$opt}; | |||||||||||||
| 22 | |||||||||||||||
| 23 | 0 | ▶ | if ( $opt{'dict'} eq 'sindarin-english' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | open( my $file, '<:encoding(UTF-8)', 'data/sindeng.txt' ); | |||||||||||||
| 26 | 0 | $self->dictionary(&parse_file($file)); | |||||||||||||
| 27 | |||||||||||||||
| 28 | } elsif ( $opt{'dict'} eq 'english-sindarin' ) { | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | open( my $file, '<:encoding(UTF-8)', 'data/engsind.txt' ); | |||||||||||||
| 31 | 0 | $self->dictionary(&parse_file($file)); | |||||||||||||
| 32 | |||||||||||||||
| 33 | } else { | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 0 | warn "Unknown option"; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 0 | ▶ | sub parse_file { | ||||||||||||
|
Subroutine
parse_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||
| 41 | 0 | my $file = shift; | |||||||||||||
| 42 | |||||||||||||||
| 43 | 0 | my @map; | |||||||||||||
| 44 | |||||||||||||||
| 45 | 0 | ▶ | while ( my $line = <$file> ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | |||||||||||||||
| 47 | 0 | ▶ | if ( $line =~ m/^(\w+)[,-]?:\s(.+)/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | 0 | push(@map, $line); | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 0 | return \@map; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | |||||||||||||||
| 56 | 0 | ▶ | sub search { | ||||||||||||
|
Subroutine
search: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||
| 58 | 0 | chomp (my $word = shift); | |||||||||||||
| 59 | |||||||||||||||
| 60 | 0 | my @map = @{$self->dictionary}; | |||||||||||||
| 61 | 0 | my $result = ''; | |||||||||||||
| 62 | |||||||||||||||
| 63 | 0 | for my $entry ( @map ) { | |||||||||||||
| 64 | |||||||||||||||
| 65 | 0 | ▶ | if ( $entry =~ m/^($word)[,-]?:\s(.+)/i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | |||||||||||||||
| 67 | 0 | $result .= $2."\n"; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | ▶ | if ( $result eq "" ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 0 | say "Word not found"; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | return $result; | |||||||||||||
| 76 | |||||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 1 | 1; | |||||||||||||