| 1 | package Yandex::Dictionary; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use HTML::Entities qw{encode_entities}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use POSIX qw{:locale_h}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use URI::Escape qw{uri_escape_utf8}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | my | ||||||||||||||||||||||||||||||||||||||
| 14 | 8 | $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 8 | my %valid_lang = map { $_ => 1 } qw{ | |||||||||||||||||||||||||||||||||||||
| 17 | be-be be-ru bg-ru cs-en cs-ru da-en da-ru de-de de-en | ||||||||||||||||||||||||||||||||||||||
| 18 | de-ru de-tr el-en el-ru en-cs en-da en-de en-el en-en | ||||||||||||||||||||||||||||||||||||||
| 19 | en-es en-et en-fi en-fr en-it en-lt en-lv en-nl en-no | ||||||||||||||||||||||||||||||||||||||
| 20 | en-pt en-ru en-sk en-sv en-tr en-uk es-en es-es es-ru | ||||||||||||||||||||||||||||||||||||||
| 21 | et-en et-ru fi-en fi-fi fi-ru fr-en fr-fr fr-ru hu-hu | ||||||||||||||||||||||||||||||||||||||
| 22 | hu-ru it-en it-it it-ru lt-en lt-lt lt-ru lv-en lv-ru | ||||||||||||||||||||||||||||||||||||||
| 23 | mhr-ru mrj-ru nl-en nl-ru no-en no-ru pl-ru pt-en pt-ru | ||||||||||||||||||||||||||||||||||||||
| 24 | ru-be ru-bg ru-cs ru-da ru-de ru-el ru-en ru-es ru-et | ||||||||||||||||||||||||||||||||||||||
| 25 | ru-fi ru-fr ru-hu ru-it ru-lt ru-lv ru-mhr ru-mrj ru-nl | ||||||||||||||||||||||||||||||||||||||
| 26 | ru-no ru-pl ru-pt ru-ru ru-sk ru-sv ru-tr ru-tt ru-uk | ||||||||||||||||||||||||||||||||||||||
| 27 | sk-en sk-ru sv-en sv-ru tr-de tr-en tr-ru tt-ru uk-en | ||||||||||||||||||||||||||||||||||||||
| 28 | uk-ru uk-uk | ||||||||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 8 | my %valid_default_ui = map { $_ => 1 } qw{ en ru tr }; | |||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | 8 | my %valid_format = map { $_ => 1 } qw{ json xml }; | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 8 | my $default_format = 'json'; | |||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | my $james_axl_result = sub | ||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | die "You must set API key\n" if (not defined $self->{ _key_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | die "You must set Text\n" if (not defined $self->{ _text_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $query = '/lookup?'; | |||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $post = 'key='.$self->{ _key_ }.'&text='.$self->{ _text_ }.'&lang='.$self->{_lang_}.'&ui='.$self->{_ui_}; | |||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $response = $self->{_http_}->get($self->{_base_} . '.json' . $query . $post); | |||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | die "Invalid API key.\n" if ($response->{status} eq '401'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | die "Blocked API key.\n" if ($response->{status} eq '402'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | die "Exceeded the daily limit on the number of requests.\n" if ($response->{status} eq '403'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | die "The text size exceeds the maximum.\n" if ($response->{status} eq '413'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | die "The specified translation direction is not supported.\n" if ($response->{status} eq '501'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | die "Failed to get list of supported languages! (response code $response->{status})\n" unless ($response->{success}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (defined wantarray && length $response->{content}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined wantarray and length $response->{"content"}
MC/DC0%0/2
defined wantarray and length $response->{"content"}
defined wantarray
length $response->{"content"}
Truth table0%0/3
A and B
A= defined wantarrayB= length $response->{"content"}
| |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $json_respond = JSON->new->utf8->decode($response->{content}); | |||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $json_respond->{def}; | |||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||
| 55 | 8 | }; | |||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||
| 58 | ## Set the default UI to Russian if the locale is Russian; | ||||||||||||||||||||||||||||||||||||||
| 59 | ## Set the default UI to Turkish if the locale is Turkish; | ||||||||||||||||||||||||||||||||||||||
| 60 | ## otherwise, set it to English. | ||||||||||||||||||||||||||||||||||||||
| 61 | ## | ||||||||||||||||||||||||||||||||||||||
| 62 | # | ||||||||||||||||||||||||||||||||||||||
| 63 | 8 | ▶ | (my $default_ui = setlocale(LC_CTYPE) || 'en') =~ s/_.*$//; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
setlocale(0) || 'en'
MC/DC0%0/1
setlocale(0) || 'en'
setlocale(0)
Truth table50%1/2
A
A= setlocale(0)
| |||||||||||||||||||||||||||||||||||||||
| 64 | 8 | ▶ | $default_ui = 'en' if (!exists $valid_default_ui{$default_ui}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | sub new | ||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my $self = { | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
shift() || $default_ui
shift() || $default_format
MC/DC0%0/2
shift() || $default_ui
shift()
$default_ui
MC/DC0%0/2
shift() || $default_format
shift()
$default_format
Truth table0%0/3
A || B
A= shift()B= $default_ui
Truth table0%0/3
A || B
A= shift()B= $default_format
| |||||||||||||||||||||||||||||||||||||||
| 70 | _key_ => shift, | ||||||||||||||||||||||||||||||||||||||
| 71 | _text_ => shift, | ||||||||||||||||||||||||||||||||||||||
| 72 | _lang_ => shift, | ||||||||||||||||||||||||||||||||||||||
| 73 | _ui_ => shift || $default_ui, | ||||||||||||||||||||||||||||||||||||||
| 74 | _format_ => shift || $default_format, | ||||||||||||||||||||||||||||||||||||||
| 75 | _base_ => 'https://dictionary.yandex.net/api/v1/dicservice' , | ||||||||||||||||||||||||||||||||||||||
| 76 | _http_ => HTTP::Tiny->new, | ||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $self->{_text_} = uri_escape_utf8($self->{_text_}) if (defined $self->{_text_}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | sub set_key | ||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_key: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my ($self,$key) = @_; | |||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $self->{_key_} = $key if (defined $key); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | sub set_text | ||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_text: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my ($self,$test) = @_; | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | $self->{_text_} = $test if (defined $test); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | sub set_lang | ||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_lang: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my ($self,$lang) = @_; | |||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $self->{_lang_} = $lang if (defined $lang && exists $valid_lang{$lang}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lang and exists $valid_lang{$lang}
MC/DC0%0/2
defined $lang and exists $valid_lang{$lang}
defined $lang
exists $valid_lang{$lang}
Truth table0%0/3
A and B
A= defined $langB= exists $valid_lang{$lang}
| |||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | sub set_format | ||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_format: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($self,$format) = @_; | |||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $self->{_format_} = (defined $format && exists $valid_format{$format}) ? $format : $default_format; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $format and exists $valid_format{$format}
MC/DC0%0/2
defined $format and exists $valid_format{$format}
defined $format
exists $valid_format{$format}
Truth table0%0/3
A and B
A= defined $formatB= exists $valid_format{$format}
| |||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | sub set_ui | ||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_ui: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my ($self,$ui) = @_; | |||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{_ui_} = (defined $ui && exists $valid_default_ui{$ui}) ? $ui : $default_ui; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ui and exists $valid_default_ui{$ui}
MC/DC0%0/2
defined $ui and exists $valid_default_ui{$ui}
defined $ui
exists $valid_default_ui{$ui}
Truth table0%0/3
A and B
A= defined $uiB= exists $valid_default_ui{$ui}
| |||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | sub set_default_ui | ||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
set_default_ui: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my ($self,$this_default_ui) = @_; | |||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $default_ui = $this_default_ui if (defined $this_default_ui && exists $valid_default_ui{$this_default_ui}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $this_default_ui and exists $valid_default_ui{$this_default_ui}
MC/DC0%0/2
defined $this_default_ui and exists $valid_default_ui{$this_default_ui}
defined $this_default_ui
exists $valid_default_ui{$this_default_ui}
Truth table0%0/3
A and B
A= defined $this_default_uiB= exists $valid_default_ui{$this_default_ui}
| |||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||
| 119 | sub get_langs_list | ||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_langs_list: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | die "You must set API key\n" if (not defined $self->{ _key_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $query = '/getLangs?'; | |||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $post = 'key='.$self->{_key_}.'&ui='.$self->{_ui_}; | |||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $self->{_format_} = (defined $self->{_format_} && exists $valid_format{$self->{_format_}}) ? $self->{_format_} :$default_format; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"_format_"} and exists $valid_format{$self->{"_format_"}}
MC/DC0%0/2
defined $self->{"_format_"} and exists $valid_format{$self->{"_format_"}}
defined $self->{"_format_"}
exists $valid_format{$self->{"_format_"}}
Truth table0%0/3
A and B
A= defined $self->{"_format_"}B= exists $valid_format{$self->{"_format_"}}
| |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $format = ($self->{_format_} eq 'xml') ? '' : '.json'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $response = $self->{_http_}->get($self->{_base_} . $format . $query . $post); | |||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | die "Invalid API key\n" if ($response->{status} eq '401'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | die "Blocked API key\n" if ($response->{status} eq '402'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | die "Failed to get list of supported languages! (response code $response->{status})\n" unless ($response->{success}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (length $response->{content}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return $response->{content}; | |||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||
| 138 | sub james_axl_langs_list | ||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
james_axl_langs_list: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | die "You must set API key\n" if (not defined $self->{ _key_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | die "You must set Text\n" if (not defined $self->{ _text_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $query = '/getLangs?'; | |||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $post = 'key='.$self->{_key_}.'&ui='.$self->{_ui_}; | |||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $response = $self->{_http_}->get($self->{_base_} .'.json' . $query . $post); | |||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | die "Invalid API key\n" if ($response->{status} eq '401'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | die "Blocked API key\n" if ($response->{status} eq '402'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | die "Failed to get list of supported languages! (response code $response->{status})\n" unless ($response->{success}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (defined wantarray && length $response->{content}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined wantarray and length $response->{"content"}
MC/DC0%0/2
defined wantarray and length $response->{"content"}
defined wantarray
length $response->{"content"}
Truth table0%0/3
A and B
A= defined wantarrayB= length $response->{"content"}
| |||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $json_respond = JSON->new->utf8->decode($response->{content}); | |||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return (wantarray) ? @{ $json_respond } : scalar(@{ $json_respond }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | sub get_result | ||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_result: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | die "You must set API key\n" if (not defined $self->{ _key_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | die "You must set Text\n" if (not defined $self->{ _text_ }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $query = '/lookup?'; | |||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $post = 'key='.$self->{ _key_ }.'&text='.$self->{ _text_ }.'&lang='.$self->{_lang_}.'&ui='.$self->{_ui_}; | |||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $self->{_format_} = $default_format if (defined $self->{_format_} && !exists $valid_format{$self->{_format_}}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"_format_"} and not exists $valid_format{$self->{"_format_"}}
MC/DC0%0/2
defined $self->{"_format_"} and not exists $valid_format{$self->{"_format_"}}
defined $self->{"_format_"}
not exists $valid_format{$self->{"_format_"}}
Truth table0%0/3
A and not(B)
A= defined $self->{"_format_"}B= not exists $valid_format{$self->{"_format_"}}
| |||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $format = ($self->{_format_} eq 'xml') ? '' : '.json'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $response = $self->{_http_}->get($self->{_base_} . $format . $query . $post); | |||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | die "Invalid API key.\n" if ($response->{status} eq '401'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | die "Blocked API key.\n" if ($response->{status} eq '402'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | die "Exceeded the daily limit on the number of requests.\n" if ($response->{status} eq '403'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | die "The text size exceeds the maximum.\n" if ($response->{status} eq '413'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | die "The specified translation direction is not supported.\n" if ($response->{status} eq '501'); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | die "Failed to get list of supported languages! (response code $response->{status})\n" unless ($response->{success}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if (length $response->{content}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return $response->{content}; | |||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | sub get_input_text_pos_ts | ||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_input_text_pos_ts: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $respond = $self->$james_axl_result(); | |||||||||||||||||||||||||||||||||||||
| 180 | 0 | my $index = undef; | |||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $result = []; | |||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | for ($index = 0; $index < scalar @{$respond} ; $index+=1){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 183 | 0 | push @{$result}, { | |||||||||||||||||||||||||||||||||||||
| 184 | 0 | 'text' => ${$respond}[$index]->{text}, | |||||||||||||||||||||||||||||||||||||
| 185 | 0 | 'pos' => ${$respond}[$index]->{pos}, | |||||||||||||||||||||||||||||||||||||
| 186 | 0 | 'ts' => ${$respond}[$index]->{ts} | |||||||||||||||||||||||||||||||||||||
| 187 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return (wantarray) ? @{ $result } : scalar(@{ $result }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||
| 193 | # In English does not have 'gen' | ||||||||||||||||||||||||||||||||||||||
| 194 | sub get_result_tr_pos_gen | ||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_result_tr_pos_gen: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $respond = $self->$james_axl_result(); | |||||||||||||||||||||||||||||||||||||
| 198 | 0 | my ($x,$y,$result) = (undef, undef, []); | |||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | for ($x = 0; $x < scalar @{$respond} ; $x+=1){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | for ($y = 0; $y < scalar @{$respond->[$x]->{tr}} ; $y+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 202 | 0 | push @{$result}, { | |||||||||||||||||||||||||||||||||||||
| 203 | 0 | 'text' => ${$respond}[$x]->{tr}[$y]->{text}, | |||||||||||||||||||||||||||||||||||||
| 204 | 0 | 'pos' => ${$respond}[$x]->{tr}[$y]->{pos}, | |||||||||||||||||||||||||||||||||||||
| 205 | 0 | 'gen' => ${$respond}[$x]->{tr}[$y]->{gen} | |||||||||||||||||||||||||||||||||||||
| 206 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | return (wantarray) ? @{ $result } : scalar(@{ $result }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||
| 213 | sub get_result_mean | ||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_result_mean: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $respond = $self->$james_axl_result(); | |||||||||||||||||||||||||||||||||||||
| 217 | 0 | my ($x,$y,$z,$result) = (undef, undef, undef ,[]); | |||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | for ($x = 0; $x < scalar @{$respond} ; $x+=1){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | for ($y = 0; $y < scalar @{$respond->[$x]->{tr}} ; $y+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if (defined ${$respond}[$x]->{tr}[$y]->{mean}[0]->{text}){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | for ($z = 0; $z < scalar @{$respond->[$x]->{tr}->[$y]->{mean}} ; $z+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 222 | 0 | push @{$result}, ${$respond}[$x]->{tr}[$y]->{mean}[$z]->{text}; | |||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return (wantarray) ? @{ $result } : scalar(@{ $result }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||
| 231 | sub get_result_syn | ||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_result_syn: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $respond = $self->$james_axl_result(); | |||||||||||||||||||||||||||||||||||||
| 235 | 0 | my ($x,$y,$z,$result) = (undef, undef, undef ,[]); | |||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | for ($x = 0; $x < scalar @{$respond} ; $x+=1){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | for ($y = 0; $y < scalar @{$respond->[$x]->{tr}} ; $y+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (defined ${$respond}[$x]->{tr}[$y]->{syn}[0]->{text}){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | for ($z = 0; $z < scalar @{$respond->[$x]->{tr}->[$y]->{syn}} ; $z+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 240 | 0 | push @{$result}, { | |||||||||||||||||||||||||||||||||||||
| 241 | 0 | 'text' => ${$respond}[$x]->{tr}[$y]->{syn}[$z]->{text}, | |||||||||||||||||||||||||||||||||||||
| 242 | 0 | 'pos' => ${$respond}[$x]->{tr}[$y]->{syn}[$z]->{pos}, | |||||||||||||||||||||||||||||||||||||
| 243 | 0 | 'gen' => ${$respond}[$x]->{tr}[$y]->{syn}[$z]->{gen} | |||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||
| 245 | 0 | } | |||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | return (wantarray) ? @{ $result } : scalar(@{ $result }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | sub get_result_eg | ||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
get_result_eg: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $respond = $self->$james_axl_result(); | |||||||||||||||||||||||||||||||||||||
| 257 | 0 | my ($x,$y,$z,$result) = (undef, undef, undef ,[]); | |||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | for ($x = 0; $x < scalar @{$respond} ; $x+=1){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | for ($y = 0; $y < scalar @{$respond->[$x]->{tr}} ; $y+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (defined ${$respond}[$x]->{tr}[$y]->{ex}[0]->{text}){ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | for ($z = 0; $z < scalar @{$respond->[$x]->{tr}->[$y]->{ex}} ; $z+=1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 262 | 0 | push @{$result}, { | |||||||||||||||||||||||||||||||||||||
| 263 | 0 | 'text' => ${$respond}[$x]->{tr}[$y]->{ex}[$z]->{text}, | |||||||||||||||||||||||||||||||||||||
| 264 | 0 | 'tr' => ${$respond}[$x]->{tr}[$y]->{ex}[$z]->{tr}[0]->{text} | |||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||
| 266 | 0 | } | |||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | return (wantarray) ? @{ $result } : scalar(@{ $result }); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | 8 | 1; | |||||||||||||||||||||||||||||||||||||
| 275 | __END__ | ||||||||||||||||||||||||||||||||||||||