blib/lib/Zuzu/Value/BinaryString.pm

filter: Statementstmt 85.3% 35 / 41 Branchbran 66.6% 4 / 6 Conditioncond 37.5% 6 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 7 totaltotal 59.7% 55 / 92 CC 12 SCAR 11.1
CC
12
Cov
71%
__ANON__
6.0
to_String
6.0
to_Boolean
6.0
CRAP 3.0
« blib/lib/Zuzu/Module/Base64.pm ↑ Summary blib/lib/Zuzu/Util/Number.pm »
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 // ""
l!l
00
MC/DC0%0/1
$_[0]->bytes // ""
$_[0]->bytes
Truth table0%0/2
A
A= $_[0]->bytes
Aresult
11
00
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 // ""
l!l
1140
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
Aresult
11
00
20 114 ▶ utf8::encode( $bytes ) if utf8::is_utf8( $bytes );
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($bytes) 8 106 114
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 //= ""
l!l
330
MC/DC0%0/1
$text //= ""
$text
Truth table50%1/2
A
A= $text
Aresult
11
00
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 // ""
l!l
110
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
Aresult
11
00
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 // ""
l!l
40
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
Aresult
11
00
43  
44 4 ▶ return $bytes !~ /[^\x00-\x7F]/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
!($bytes =~ /[^\x00-\x7F]/) ? : 2 2 4
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 // ""
l!l
150
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
Aresult
11
00
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 // ""
l!l
00
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table0%0/2
A
A= $self->bytes
Aresult
11
00
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
BranchTrueFalseTotal
$self->byte_length ? : 0 0 0
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 // ""
l!l
60
MC/DC0%0/1
$self->bytes // ""
$self->bytes
Truth table50%1/2
A
A= $self->bytes
Aresult
11
00
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
« blib/lib/Zuzu/Module/Base64.pm ↑ Summary blib/lib/Zuzu/Util/Number.pm »