File Coverage

blib/lib/SPVM/BlessedObject/String.pm
Criterion Covered Total %
statement 31 32 96.8
branch 3 4 75.0
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 45 47 95.7


line stmt bran cond sub pod time code
1             package SPVM::BlessedObject::String;
2              
3 278     11038   1992 use strict;
  278         596  
  278         8042  
4 278     278   1423 use warnings;
  278         546  
  278         7237  
5              
6 278     278   1432 use Carp 'confess';
  278         575  
  278         12048  
7              
8 278     278   2079 use base 'SPVM::BlessedObject';
  278         820  
  278         39761  
9              
10 278     278   2162 use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
  278     23448   729  
  278         3275  
  3186         8323  
  50466         230139  
11              
12 278     278   24673 use SPVM::ExchangeAPI;
  278         606  
  278         46673  
13              
14             sub to_string {
15 63772     63772 1 90734 my $self = shift;
16            
17 63772         104621 my $string = $self->to_bin;
18            
19 63772         189067 my $success = utf8::decode($string);
20            
21 63772 100       114212 unless ($success) {
22 2         206 confess "The SPVM::BlessedObject::String object cannnot be decoded to Perl string";
23             }
24            
25 63770         282945 return $string;
26             }
27              
28 63784 50   63784 1 81322 sub to_bin { my $ret; eval { $ret = shift->_xs_to_bin(@_) }; if ($@) { confess $@ } $ret; }
  63784         90052  
  63784         299692  
  63784         133065  
  0         0  
  63784         113181  
29              
30             1;
31              
32             =head1 Name
33              
34             SPVM::BlessedObject::String - SPVM string
35              
36             =head1 Description
37              
38             The object of the C class holds a 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.
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.
77              
78             =head1 Copyright & License
79              
80             Copyright (c) 2023 Yuki Kimoto
81              
82             MIT License