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     7596   1868 use strict;
  278         558  
  278         7929  
4 278     278   1311 use warnings;
  278         571  
  278         6869  
5              
6 278     278   1370 use Carp 'confess';
  278         564  
  278         11853  
7              
8 278     278   2055 use base 'SPVM::BlessedObject';
  278         821  
  278         38486  
9              
10 278     278   2053 use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
  278     30911   1028  
  278         3134  
  3246         8510  
  52412         232549  
11              
12 278     278   23936 use SPVM::ExchangeAPI;
  278         609  
  278         45266  
13              
14             sub to_string {
15 66326     66326 1 93617 my $self = shift;
16            
17 66326         106898 my $string = $self->to_bin;
18            
19 66326         200235 my $success = utf8::decode($string);
20            
21 66326 100       118635 unless ($success) {
22 2         240 confess "The SPVM::BlessedObject::String object cannnot be decoded to Perl string";
23             }
24            
25 66324         280697 return $string;
26             }
27              
28 66338 50   66338 1 82916 sub to_bin { my $ret; eval { $ret = shift->_xs_to_bin(@_) }; if ($@) { confess $@ } $ret; }
  66338         92706  
  66338         309594  
  66338         137697  
  0         0  
  66338         115528  
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