| 1 | package Lingua::Boolean; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DEPRECATED module to comprehensively parse boolean response strings | ||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use experimental qw/smartmatch/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | our $VERSION = '0.008'; # VERSION | |||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use boolean 0.21 qw(true false); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use String::Trim qw(trim); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Module::Load qw(load); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 7 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 7 | our @EXPORT = qw(boolean); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 85 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 85 | my $class = shift; | |||||||||||||||||||||||||||
| 21 | 85 | my $lang = shift; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 85 | my $objects; | |||||||||||||||||||||||||||
| 24 | 85 | BUILD: foreach my $plugin ( map { __PACKAGE__ . "::$_" } qw/ English French / ) { | |||||||||||||||||||||||||||
| 25 | 170 | load $plugin; | |||||||||||||||||||||||||||
| 26 | 170 | my $obj = $plugin->new(); | |||||||||||||||||||||||||||
| 27 | 170 | ▶ | next BUILD if (defined $lang and $obj->{LANG} ne $lang); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $lang and $obj->{"LANG"} ne $lang
MC/DC100%2/2
defined $lang and $obj->{"LANG"} ne $lang
defined $lang
$obj->{"LANG"} ne $lang
Truth table100%3/3
A and B
A= defined $langB= $obj->{"LANG"} ne $lang
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 104 | $objects->{ $obj->{LANG} } = $obj; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 85 | my $self = { | |||||||||||||||||||||||||||
| 33 | languages => $objects, | ||||||||||||||||||||||||||||
| 34 | lang => $lang, | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | 85 | bless $self, $class; | |||||||||||||||||||||||||||
| 37 | 85 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 211 | ▶ | sub _boolean { | ||||||||||||||||||||||||||
|
Subroutine
_boolean: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 42 | 211 | my $self = shift; | |||||||||||||||||||||||||||
| 43 | 211 | my $to_test = shift; | |||||||||||||||||||||||||||
| 44 | 211 | ▶ | my $lang = shift || 'en'; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 'en'
MC/DC100%1/1
shift() || 'en'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 45 | 211 | trim($to_test); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 211 | ▶ | if ($self->_looks_true($to_test, $lang)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 48 | 80 | return true; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | elsif ($self->_looks_false($to_test, $lang)) { | ||||||||||||||||||||||||||||
| 51 | 75 | return false; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | else { | ||||||||||||||||||||||||||||
| 54 | 18 | croak "'$to_test' isn't recognizable as either true or false"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 211 | ▶ | sub boolean { | ||||||||||||||||||||||||||
|
Subroutine
boolean: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 211 | ▶ | my $self = ref $_[0] eq __PACKAGE__ ? shift : __PACKAGE__->new($_[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 211 | my $to_test = shift; | |||||||||||||||||||||||||||
| 61 | 211 | ▶ | my $lang = shift || $self->{lang}; | ||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self->{'lang'}
MC/DC50%1/2
shift() || $self->{'lang'}
shift()
$self->{'lang'}
Truth table66%2/3
A || B
A= shift()B= $self->{'lang'}
| |||||||||||||||||||||||||||||
| 62 | 211 | trim($to_test); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 211 | return $self->_boolean($to_test, $lang); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | sub languages { | ||||||||||||||||||||||||||
|
Subroutine
languages: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 4 | ▶ | my $self = ref $_[0] eq __PACKAGE__ ? shift : __PACKAGE__->new(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | my @long_names; | |||||||||||||||||||||||||||
| 72 | 4 | foreach my $l (keys %{ $self->{languages} }) { | |||||||||||||||||||||||||||
| 73 | 8 | push @long_names, $self->{languages}->{$l}->{LANGUAGE}; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 4 | return @long_names; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 4 | ▶ | sub langs { | ||||||||||||||||||||||||||
|
Subroutine
langs: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 4 | ▶ | my $self = ref $_[0] eq __PACKAGE__ ? shift : __PACKAGE__->new(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 4 | my @lang_codes = keys %{ $self->{languages} }; | |||||||||||||||||||||||||||
| 83 | 4 | return @lang_codes; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 211 | ▶ | sub _looks_true { | ||||||||||||||||||||||||||
|
Subroutine
_looks_true: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 88 | 211 | my $self = shift; | |||||||||||||||||||||||||||
| 89 | 211 | my $to_test = shift; | |||||||||||||||||||||||||||
| 90 | 211 | ▶ | my $lang = shift || 'en'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'en'
MC/DC0%0/1
shift() || 'en'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 91 | 211 | trim($to_test); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 211 | ▶ | croak "I don't know anything about the language '$lang'" unless exists $self->{languages}->{$lang}->{match}->{True}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 173 | ▶ | return true if ($to_test ~~ $self->{languages}->{$lang}->{match}->{True}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 93 | return false; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 93 | ▶ | sub _looks_false { | ||||||||||||||||||||||||||
|
Subroutine
_looks_false: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 99 | 93 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 93 | my $to_test = shift; | |||||||||||||||||||||||||||
| 101 | 93 | ▶ | my $lang = shift || 'en'; | ||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'en'
MC/DC0%0/1
shift() || 'en'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 102 | 93 | trim($to_test); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 93 | ▶ | croak "I don't know anything about the language '$lang'" unless exists $self->{languages}->{$lang}->{match}->{False}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 93 | ▶ | return true if ($to_test ~~ $self->{languages}->{$lang}->{match}->{False}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 18 | return false; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 7 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||