| 1 | package Zuzu::Value::BinaryString; | ||||||||||||
| 2 | |||||||||||||
| 3 | 79 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 79 | our $VERSION = '0.007002'; | |||||||||||
| 6 | |||||||||||||
| 7 | 79 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 79 | ▶ | use Encode (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | use overload | ||||||||||||
| 11 | 0 | ▶ | '""' => sub { $_[0]->bytes // '' }, | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]->bytes // ""
MC/DC0%0/1
$_[0]->bytes // ""
$_[0]->bytes
Truth table0%0/2
A
A= $_[0]->bytes
| |||||||||||||
| 12 | 79 | fallback => 1; | |||||||||||
| 13 | |||||||||||||
| 14 | 0 | ▶ | has 'bytes' => ( is => 'rw', default => sub { '' } ); | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 15 | |||||||||||||
| 16 | 114 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 17 | 114 | my ( $self ) = @_; | |||||||||||
| 18 | |||||||||||||
| 19 | 114 | ▶ | my $bytes = $self->bytes // ''; | ||||||||||
|
Condition50%1/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
| |||||||||||||
| 20 | 114 | ▶ | utf8::encode( $bytes ) if utf8::is_utf8( $bytes ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 114 | $self->bytes( $bytes ); | |||||||||||
| 22 | |||||||||||||
| 23 | 114 | return; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 33 | ▶ | sub from_utf8_string { | ||||||||||
|
Subroutine
from_utf8_string: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 27 | 33 | my ( $class, $text ) = @_; | |||||||||||
| 28 | 33 | ▶ | $text //= ''; | ||||||||||
|
Condition50%1/2
$text //= ""
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||
| 29 | 33 | my $bytes = Encode::encode( 'UTF-8', $text, Encode::FB_CROAK ); | |||||||||||
| 30 | |||||||||||||
| 31 | 33 | return $class->new( bytes => $bytes ); | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 11 | ▶ | sub byte_length { | ||||||||||
|
Subroutine
byte_length: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||
| 35 | 11 | my ( $self ) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 11 | ▶ | return length( $self->bytes // '' ); | ||||||||||
|
Condition50%1/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
| |||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 4 | ▶ | sub is_ascii { | ||||||||||
|
Subroutine
is_ascii: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||
| 41 | 4 | my ( $self ) = @_; | |||||||||||
| 42 | 4 | ▶ | my $bytes = $self->bytes // ''; | ||||||||||
|
Condition50%1/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
| |||||||||||||
| 43 | |||||||||||||
| 44 | 4 | ▶ | return $bytes !~ /[^\x00-\x7F]/ ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | 15 | ▶ | sub to_utf8_string { | ||||||||||
|
Subroutine
to_utf8_string: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 48 | 15 | my ( $self ) = @_; | |||||||||||
| 49 | 15 | ▶ | my $bytes = $self->bytes // ''; | ||||||||||
|
Condition50%1/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
| |||||||||||||
| 50 | |||||||||||||
| 51 | 15 | return Encode::decode( 'UTF-8', $bytes, Encode::FB_CROAK ); | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | sub to_String { | ||||||||||
|
Subroutine
to_String: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 55 | 0 | my ( $self ) = @_; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | return $self->bytes // ''; | ||||||||||
|
Condition0%0/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table0%0/2
A
A= $self->bytes
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | sub to_Boolean { | ||||||||||
|
Subroutine
to_Boolean: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 61 | 0 | my ( $self ) = @_; | |||||||||||
| 62 | |||||||||||||
| 63 | 0 | ▶ | return $self->byte_length ? 1 : 0; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 6 | ▶ | sub _stable_key { | ||||||||||
|
Subroutine
_stable_key: called CC=2 SCAR=7.1
| |||||||||||||
| 67 | 6 | my ( $self ) = @_; | |||||||||||
| 68 | 6 | ▶ | my $bytes = $self->bytes // ''; | ||||||||||
|
Condition50%1/2
$self->bytes // ""
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
| |||||||||||||
| 69 | |||||||||||||
| 70 | 6 | return unpack( 'H*', $bytes ); | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 79 | 1; | |||||||||||
| 74 | |||||||||||||
| 75 | =pod | ||||||||||||
| 76 | |||||||||||||
| 77 | =head1 COPYRIGHT AND LICENCE | ||||||||||||
| 78 | |||||||||||||
| 79 | B<< Zuzu::Value::BinaryString >> is copyright Toby Inkster. | ||||||||||||
| 80 | |||||||||||||
| 81 | It is free software; you may redistribute it and/or modify it under | ||||||||||||
| 82 | the terms of either the Artistic License 1.0 or the GNU General Public | ||||||||||||
| 83 | License version 2. | ||||||||||||
| 84 | |||||||||||||
| 85 | =cut | ||||||||||||