| 1 | package SPVM::BlessedObject::String; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 523 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 556 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 522 | ▶ | use Carp 'confess'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 556 | ▶ | use base 'SPVM::BlessedObject'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 522 | ▶ | use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | |||||||||||||||
| 12 | 776 | ▶ | use SPVM::ExchangeAPI; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 460 | ▶ | sub to_string { | ||||||||||||
|
Subroutine
to_string: called CC=2 SCAR=10.0
Pod
documented
| |||||||||||||||
| 15 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
to_string: not called CC=2 SCAR=10.0
Pod
documented
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | my $string = $self->to_bin; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 0 | my $success = utf8::decode($string); | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | unless ($success) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 22 | 0 | confess("The SPVM::BlessedObject::String object cannnot be decoded to Perl string"); | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 0 | return $string; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 460 | ▶ | 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
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | 522 | 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 | ||||||||||||||