File Coverage

blib/lib/SPVM/Builder/Resource.pm
Criterion Covered Total %
statement 43 48 89.5
branch 8 10 80.0
condition 1 3 33.3
subroutine 13 14 92.8
pod 6 6 100.0
total 71 81 87.6


line stmt bran cond sub pod time code
1             package SPVM::Builder::Resource;
2              
3 283     283   3318 use strict;
  283         612  
  283         11082  
4 283     283   3011 use warnings;
  283         3205  
  283         9286  
5 283     283   1540 use Config;
  283         2020  
  283         11990  
6 283     283   2881 use Carp 'confess';
  283         2988  
  283         13881  
7 283     283   3015 use File::Basename 'dirname';
  283         2159  
  283         29193  
8              
9 283     283   3115 use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1;
  283     24   1828  
  283     0   4115  
  0         0  
  40         154  
10              
11             # Fields
12             sub class_name {
13 62     62 1 129 my $self = shift;
14 62 50       166 if (@_) {
15 0         0 $self->{class_name} = $_[0];
16 0         0 return $self;
17             }
18             else {
19 62         339 return $self->{class_name};
20             }
21             }
22              
23             sub mode {
24 14     14 1 36 my $self = shift;
25 14 50       55 if (@_) {
26 0         0 $self->{mode} = $_[0];
27 0         0 return $self;
28             }
29             else {
30 14         94 return $self->{mode};
31             }
32             }
33              
34             sub argv {
35 35     35 1 66 my $self = shift;
36 35 100       79 if (@_) {
37 9         67 $self->{argv} = $_[0];
38 9         29 return $self;
39             }
40             else {
41 26         180 return $self->{argv};
42             }
43             }
44              
45             sub config {
46 48     48 1 141 my $self = shift;
47 48 100       159 if (@_) {
48 12         32 $self->{config} = $_[0];
49 12         25 return $self;
50             }
51             else {
52 36         197 return $self->{config};
53             }
54             }
55              
56             # Methods
57             sub new {
58 12     12 1 32 my $class = shift;
59            
60 12         51 my $self = {@_};
61            
62 12   33     106 bless $self, ref $class || $class;
63            
64 12 100       65 unless ($self->argv) {
65 9         46 $self->argv([]);
66             }
67            
68 12         52 return $self;
69             }
70              
71             sub to_string {
72 40     40 1 93 my ($self) = @_;
73            
74 40         114 return $self->class_name;
75             }
76              
77             1;
78              
79             =head1 Name
80              
81             SPVM::Builder::Resource - Resource
82              
83             =head1 Description
84              
85             The SPVM::Builder::Resource class has methods to manipulate a resource.
86              
87             =head1 Usage
88              
89             my $resource = SPVM::Builder::Resource->new(
90             class_name => 'Resource::Zlib',
91             mode => 'high_performance',
92             argv => ['foo', 'bar'],
93             );
94              
95             =head1 Fields
96              
97             =head2 class_name
98              
99             my $basic_type_name = $resource->class_name;
100             $resource->class_name($basic_type_name);
101              
102             Gets and sets the C field.
103              
104             This field is a class name of a resource.
105              
106             =head2 mode
107              
108             my $mode = $resource->mode;
109             $resource->mode($mode);
110              
111             Gets and sets the C field.
112              
113             This field is a mode of a config file of a resource.
114              
115             =head2 argv
116              
117             my $argv = $resource->argv;
118             $resource->argv($argv);
119              
120             Gets and sets the C field.
121              
122             This field is an array reference that contains command line arguments C<@ARGV> of a config file of a resource.
123              
124             =head2 config
125              
126             my $config = $resource->config;
127             $resource->config($config);
128              
129             Gets and sets the C field.
130              
131             This field is a a L object for a resource.
132              
133             =head1 Class Methods
134              
135             =head2 new
136              
137             my $resource = SPVM::Builder::Resource->new(%fields);
138              
139             Creates a L object with L.
140              
141             Default Field Values:
142              
143             If a field is not defined, the field is set to the following default value.
144              
145             =over 2
146              
147             =item * L
148              
149             undef
150              
151             =item * L
152              
153             undef
154              
155             =item * L
156              
157             []
158              
159             =item * L
160              
161             undef
162              
163             =back
164              
165             =head1 Instance Methods
166              
167             =head2 to_string
168              
169             my $string = $resource->to_string;
170              
171             Returns the L field.
172              
173             =head1 Operators
174              
175             Overloads the following operators.
176              
177             =head2 bool
178              
179             my $bool = !!$resource;
180              
181             Always true.
182              
183             =head2 stringify
184              
185             my $basic_type_name = "$resource";
186              
187             The alias for the L method.
188              
189             =head1 Copyright & License
190              
191             Copyright (c) 2023 Yuki Kimoto
192              
193             MIT License