blib/lib/SPVM/BlessedObject/String.pm

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 95.9% 47 / 49 CC 4 SCAR 3.6
CC
4
Cov
95%
to_bin
2.0
to_string
2.0
to_string
2.0
CRAP 1.4
« blib/lib/SPVM/BlessedObject/Class.pm ↑ Summary blib/lib/SPVM/Builder/Config/DLL.pm »
1 package SPVM::BlessedObject::String;
2  
3 1331 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 679 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 652 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 652 ▶use base 'SPVM::BlessedObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 28 ▶use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 652 ▶use SPVM::ExchangeAPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub to_string {
15 267 ▶ my $self = shift;
Subroutine to_string: called CC=2 SCAR=7.0
Pod documented
16
17 267 my $string = $self->to_bin;
18
19 267 my $success = utf8::decode($string);
20
21 267 ▶ unless ($success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 240 240
22 27 confess("The SPVM::BlessedObject::String object cannnot be decoded to Perl string");
23 }
24
25 267 return $string;
26 }
27  
28 267 ▶sub to_bin { my $ret; eval { $ret = shift->_xs_to_bin(@_) }; if ($@) { confess($@) } $ret; }
Subroutine to_bin: called CC=2 SCAR=7.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 240 240
29  
30 1;
31  
32 =head1 Name
33  
34 SPVM::BlessedObject::String - SPVM string
35  
36 =head1 Description
37  
38 The object of C<SPVM::BlessedObject::String> class holds an SPVM string.
39  
40 =head1 Usage
41  
42 my $string = $blessed_object_string->to_string;
43
44 my $binary = $blessed_object_string->to_bin;
45  
46 =head1 Instance Methods
47  
48 =head2 to_string
49  
50 my $string = $blessed_object_string->to_string;
51  
52 Returns a string decoded to Perl string using L<utf8::decode|https://metacpan.org/pod/utf8>.
53  
54 If the docoding fails, an exception is thrown.
55  
56 =head2 to_bin
57  
58 my $binary = $blessed_object_string->to_bin;
59  
60 Returns a string as a binary.
61  
62 =head1 Operators
63  
64 Overloads the following operators.
65  
66 =head2 bool
67  
68 my $bool = !!$blessed_object_string;
69  
70 Always true.
71  
72 =head2 stringify
73  
74 my $string = "$blessed_object_string";
75  
76 The alias for L</"to_string">.
77  
78 =head1 Copyright & License
79  
80 Copyright (c) 2023 Yuki Kimoto
81  
82 MIT License
« blib/lib/SPVM/BlessedObject/Class.pm ↑ Summary blib/lib/SPVM/Builder/Config/DLL.pm »