File Coverage

blib/lib/SPVM/BlessedObject/Class.pm
Criterion Covered Total %
statement 26 26 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 34 34 100.0


line stmt bran cond sub pod time code
1             package SPVM::BlessedObject::Class;
2              
3 278     278   2017 use strict;
  278         589  
  278         8738  
4 278     278   1432 use warnings;
  278         559  
  278         6412  
5 278     278   1418 use Carp;
  278         600  
  278         16594  
6              
7 278     278   2384 use base 'SPVM::BlessedObject';
  278         751  
  278         29723  
8              
9 278     278   2059 use SPVM::ExchangeAPI;
  278         684  
  278         68843  
10              
11             our $AUTOLOAD;
12             sub AUTOLOAD {
13 117327     117327   222869 my $self = shift;
14            
15 117327         173651 my $method_name = $AUTOLOAD;
16            
17             # If the class method is not found, AUTOLOAD is called.
18 117327 100       239581 unless (ref $self) {
19 2         13 my $basic_type_name = $self;
20 2         19 $basic_type_name =~ s/^SPVM:://;
21 2         14 $method_name =~ s/^.*:://;
22            
23 2         278 Carp::confess("The \"$method_name\" method in the \"$basic_type_name\" class is not found");
24             }
25            
26             # For a static instant method call
27 117325         435478 $method_name =~ s/^SPVM:://;
28            
29             # For an instance method call
30 117325         307864 $method_name =~ s/^BlessedObject::Class:://;
31            
32 117325         276842 my $ret = $self->__api->call_method($self, $method_name, @_);
33            
34 117319         3678902 return $ret;
35             }
36              
37             1;
38              
39             =head1 Name
40              
41             SPVM::BlessedObject::Class - SPVM Class
42              
43             =head1 Description
44              
45             The object of the C class holds an instance of a SPVM class.
46              
47             =head1 Usage
48              
49             use SPVM 'Point';
50            
51             my $point = SPVM::Point->new;
52             $point->set_x(4);
53             my $x = $point->x;
54             $point->clear;
55              
56             =head1 Instance Methods
57              
58             =head2 AUTOLOAD
59            
60             # Instance method call
61             my $ret = $blessed_object_class->foo(@args);
62            
63             # Static instance method call
64             my $ret = $blessed_object_class->SPVM::MyClass::foo(@args);
65              
66             Calls a SPVM instance method using L with the arguments, and returns the return value.
67              
68             The static instance method call is allowed.
69              
70             If the class or the method is not found, an exception is thrown.
71              
72             If the invocant cannnot be assigned to the class of the static method call, an exception is thrown.
73              
74             Examples:
75              
76             use SPVM 'Point';
77            
78             # Creates a SPVM::BlessedObject::Class object of the Point class.
79             my $point = Point->new;
80            
81             # Calls instance methods in the Point class.
82             $point->set_x(4);
83             my $x = $point->x;
84             $point->clear;
85              
86             =head1 Copyright & License
87              
88             Copyright (c) 2023 Yuki Kimoto
89              
90             MIT License