blib/lib/SPVM/BlessedObject/Class.pm

filter: Statementstmt 90.7% 39 / 43 Branchbran 25.0% 1 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 87.0% 47 / 54 CC 3 SCAR 3.8
CC
3
Cov
85%
AUTOLOAD
2.0
AUTOLOAD
2.0
BEGIN
1.0
CRAP 1.5
« blib/lib/SPVM.pm ↑ Summary blib/lib/SPVM/BlessedObject/String.pm »
1 package SPVM::BlessedObject::Class;
2  
3 764 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 743 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 743 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 743 ▶use base 'SPVM::BlessedObject';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 743 ▶use SPVM::ExchangeAPI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 our $AUTOLOAD;
12 5 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=7.1
13 21 ▶ my $self = shift;
Subroutine AUTOLOAD: called CC=2 SCAR=7.1
14
15 21 my $method_name = $AUTOLOAD;
16
17 # If the class method is not found, AUTOLOAD is called.
18 21 ▶ unless (ref $self) {
Branch: 2 branches
BranchTrueFalseTotal
unless (ref $self) 0 0 0
unless (ref $self) 0 5 5
19 0 my $basic_type_name = $self;
20 0 $basic_type_name =~ s/^SPVM:://;
21 0 $method_name =~ s/^.*:://;
22
23 0 Carp::confess("$basic_type_name#$method_name method is not found");
24 }
25
26 # For a static instant method call
27 21 $method_name =~ s/^SPVM:://;
28
29 # For an instance method call
30 21 $method_name =~ s/^BlessedObject::Class:://;
31
32 21 my ($caller_class_name, $caller_file, $caller_line) = caller;
33 21 my $caller_method_abs_name = "$caller_class_name#(Unknown)";
34 21 my $caller_info = SPVM::ExchangeAPI::CallerInfo->new(method_abs_name => $caller_method_abs_name, file => $caller_file, line => $caller_line);
35
36 21 my $ret = $self->__api->call_method($self, $method_name, @_, $caller_info);
37
38 21 return $ret;
39 }
40  
41 1;
42  
43 =head1 Name
44  
45 SPVM::BlessedObject::Class - SPVM Class
46  
47 =head1 Description
48  
49 The object of C<SPVM::BlessedObject::Class> class holds an instance of an SPVM class.
50  
51 =head1 Usage
52  
53 use SPVM 'Point';
54
55 my $point = SPVM::Point->new;
56 $point->set_x(4);
57 my $x = $point->x;
58 $point->clear;
59  
60 =head1 Instance Methods
61  
62 =head2 AUTOLOAD
63
64 # Instance method call
65 my $ret = $blessed_object_class->foo(@args);
66
67 # Static instance method call
68 my $ret = $blessed_object_class->SPVM::MyClass::foo(@args);
69  
70 Calls an SPVM instance method using L<SPVM::ExchangeAPI/"call_method"> with the arguments, and returns the return value.
71  
72 The static instance method call is allowed.
73  
74 If the class or the method is not found, an exception is thrown.
75  
76 If the invocant cannnot be assigned to the class of the static method call, an exception is thrown.
77  
78 Examples:
79  
80 use SPVM 'Point';
81
82 # Creates an SPVM::BlessedObject::Class object of the Point class.
83 my $point = Point->new;
84
85 # Calls instance methods in the Point class.
86 $point->set_x(4);
87 my $x = $point->x;
88 $point->clear;
89  
90 =head1 Copyright & License
91  
92 Copyright (c) 2023 Yuki Kimoto
93  
94 MIT License
« blib/lib/SPVM.pm ↑ Summary blib/lib/SPVM/BlessedObject/String.pm »