| 1 | package SPVM::ExchangeAPI::Class; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1484 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 742 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | # Fields | ||||||||||||||||||||||||||||||||||||||
| 6 | 0 | ▶ | sub __name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__name: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||
| 7 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__name: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||
| 8 | 22 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 9 | 0 | $self->{__name} = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 10 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||
| 12 | else { | ||||||||||||||||||||||||||||||||||||||
| 13 | 0 | return $self->{__name}; | |||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub __api { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__api: not called CC=2 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__api: called CC=2 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $self->{__api} = $_[0]; | |||||||||||||||||||||||||||||||||||||
| 21 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||||
| 24 | 0 | return $self->{__api}; | |||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | # Class Methods | ||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub __new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | bless $self, ref $class || $class; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
ref $class || $class
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||
| 39 | our $AUTOLOAD; | ||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $basic_type_name = $self->__name; | |||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $method_name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||
| 46 | 0 | $method_name =~ s/^SPVM::ExchangeAPI::Class:://; | |||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $ret = $self->__api->call_method($basic_type_name, $method_name, @_); | |||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return $ret; | |||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub DESTROY {} | ||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||
| 55 | 1; | ||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | =head1 Name | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | SPVM::ExchangeAPI::Class - Class Object | ||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | =head1 Description | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | C<SPVM::BlessedObject::Class> is a class object to call class methods. | ||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | =head1 Usage | ||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | # The same as the Int->__new(1) in the SPVM language | ||||||||||||||||||||||||||||||||||||||
| 68 | my $class = SPVM::ExchangeAPI::Class->__new(__name => 'Int', __api => $api); | ||||||||||||||||||||||||||||||||||||||
| 69 | my $value = $class->new(1); | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | It is easy to use L<SPVM::ExchangeAPI#class|SPVM::ExchangeAPI/"class">. | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | my $class = $api->class('Int'); | ||||||||||||||||||||||||||||||||||||||
| 74 | $class->new(1); | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | =head1 Fields | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | =head2 __name | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | my $name = $self->__name; | ||||||||||||||||||||||||||||||||||||||
| 81 | $self->__name($name); | ||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | Gets and sets a class name. | ||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | =head2 __api | ||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | my $api = $self->__api; | ||||||||||||||||||||||||||||||||||||||
| 88 | $self->__api($api); | ||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | Gets and sets a L<SPVM::ExchangeAPI> object. | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | =head1 Class Methods | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | =head2 __new | ||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||
| 96 | my $class = SPVM::ExchangeAPI::Class->__new(%options); | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | Creates a new C<SPVM::ExchangeAPI::Class> object. | ||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | Options: | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | =over 2 | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | =item * C<__name> : string | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | A class name | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | =item * C<__api> : SPVM::ExchangeAPI | ||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | A L<SPVM::ExchangeAPI> object | ||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | =back | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | =head1 Instance Methods | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | =head2 AUTOLOAD | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | $class->foo(@args); | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | Calls L<SPVM::ExchangeAPI#call_method|SPVM::ExchangeAPI/"call_method"> using L</"__name"> field and the method name given in C<AUTOLOAD> method. | ||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | =head1 Copyright & License | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | Copyright (c) 2023 Yuki Kimoto | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | MIT License | ||||||||||||||||||||||||||||||||||||||