« blib/lib/MarpaX/ESLIF/Value/Type.pm
↑ Summary
blib/lib/MarpaX/ESLIF/JSON/Decoder/RecognizerInterface.pm »
| 1 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Based on BSON::String v1.10.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package MarpaX::ESLIF::String; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: ESLIF String is any string value with encoding attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | our $VERSION = '6.0.35.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | my ($class, $value, $encoding) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | croak 'Undefined value' unless defined($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | croak 'Undefined encoding' unless defined($encoding); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | $value = "$value"; # Make sure it is a PV | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | $encoding = "$encoding"; # Make sure it is a PV | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # We TRUST the encoding. If user lies, behaviour will be undetermined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | my $lcEncoding = lc($encoding); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 4 | ▶ | if ($lcEncoding eq 'utf8' || $lcEncoding eq 'utf-8') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$lcEncoding eq "utf8" or $lcEncoding eq "utf-8"
MC/DC50%1/2
$lcEncoding eq "utf8" or $lcEncoding eq "utf-8"
$lcEncoding eq "utf8"
$lcEncoding eq "utf-8"
Truth table66%2/3
A or B
A= $lcEncoding eq "utf8"B= $lcEncoding eq "utf-8"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | utf8::upgrade($value) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | return bless {value => $value, encoding => $encoding}, $class | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub encoding { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encoding: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | return $_[0]->{encoding} # For performance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | return $_[0]->{value} # For performance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 11 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=5.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Unary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | q{bool} => sub { !! $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | q{""} => sub { $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | q{0+} => sub { 0+ $_[0]->{value} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | q{~} => sub { ~( $_[0]->{value} ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Binary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | ( map { $_ => eval "sub { return \$_[0]->{value} $_ \$_[1] }" } qw( + * ) ), ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $_ => eval ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Subroutine
__ANON__: not called CC=2 SCAR=17.4
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "sub { return \$_[2] ? \$_[1] $_ \$_[0]->{value} : \$_[0]->{value} $_ \$_[1] }" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } qw( - / % ** << >> x <=> cmp & | ^ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | map { $_ => eval "sub { return $_(\$_[0]->{value}) }" } ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
Subroutine
__ANON__: not called CC=1 SCAR=4.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | qw( cos sin exp log sqrt int ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | q{atan2} => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $_[2] ? atan2( $_[1], $_[0]->{value} ) : atan2( $_[0]->{value}, $_[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # Special | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 11 | fallback => 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||