blib/lib/Games/Axmud/Obj/Plugin.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 102 CC 6 SCAR 20.0
CC
6
Cov
0%
new
20.0
set_enabledFlag
12.0
name
2.0
CRAP 7.4
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::Plugin
16 # Handles Axmud plugins
17  
18 { package Games::Axmud::Obj::Plugin;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Called by GA::Client->loadPlugin
34 # Prepare a new instance of the Axmud plugin object which handles an Axmud plugin file that
35 # has been loaded
36 #
37 # Expected arguments
38 # $name - Unique name for this plugin (also the package name used in the file's
39 # header)
40 # $filePath - The full path of the plugin file
41 # $version - The version supplied by the plugin file's header
42 # $descrip - The description supplied by the plugin file's header
43 # $enabledFlag - Flag set to TRUE if the plugin starts marked enabled, FALSE if it
44 # starts marked disabled
45 #
46 # Optional arguments
47 # $author - The author string supplied by the plugin file's header ('undef' if
48 # none supplied)
49 # $copyright - The copyright string supplied by the plugin file's header ('undef' if
50 # none supplied)
51 # $require - The minimum Axmud version required to load the plugin; the initial
52 # 'v' should have been removed, if present ('undef' if none supplied)
53 # $init - Whether the plugin should be enabled or disabled, when it is loaded;
54 # value is the string 'enable' or 'disable' (already converted to
55 # lower-case; 'undef' if none supplied, default is 'enable')
56 #
57 # Return values
58 # 'undef' on improper arguments
59 # Blessed reference to the newly-created object on success
60  
61 my (
62 $class, $name, $filePath, $version, $descrip, $enabledFlag, $author, $copyright,
63 $require, $init, $check,
64 ) = @_;
65  
66 # Local variables
67 my $matchFlag;
68  
69 # Check for improper arguments
70 if (
71 ! defined $class || ! defined $name || ! defined $filePath || ! defined $version
72 || ! defined $descrip || ! defined $enabledFlag || defined $check
73 ) {
74 return $axmud::CLIENT->writeImproper($class . '->new', @_);
75 }
76  
77 # Check that $name is valid and not already in use by another component
78 if ($axmud::CLIENT->ivExists('constReservedHash', $name)) {
79  
80 return $axmud::CLIENT->writeError(
81 'Registry naming error: invalid name \'' . $name . '\'',
82 $class . '->new',
83 );
84  
85 } elsif ($axmud::CLIENT->ivExists('pluginHash', $name)) {
86  
87 return $axmud::CLIENT->writeError(
88 'Registry naming error: plugin \'' . $name . '\' already loaded',
89 $class . '->new',
90 );
91 }
92  
93 # Setup
94 my $self = {
95 _objName => $name,
96 _objClass => $class,
97 _parentFile => undef, # No parent file
98 _parentWorld => undef, # No parent world
99 _privFlag => TRUE, # All IVs are private
100  
101 # Object IVs
102 # ----------
103  
104 # Unique name for this plugin (also the package name used in the file's header)
105 name => $name,
106 # The version supplied by the plugin file's header
107 version => $version,
108 # The description supplied by the plugin file's header
109 descrip => $descrip,
110 # The author string supplied by the plugin file's header
111 author => $author,
112 # The copyright string supplied by the plugin file's header
113 copyright => $copyright,
114 # The minimum Axmud version required to load the plugin
115 require => $require,
116 # Whether the plugin should be enabled or disabled, when it is loaded; value is the
117 # string 'enable' or 'disable'
118 init => $init,
119  
120 # The full path of the plugin file
121 filePath => $filePath,
122 # Flag set to TRUE if the plugin is marked enabled, FALSE if it is marked disabled
123 enabledFlag => $enabledFlag,
124 };
125  
126 # Bless the object into existence
127 bless $self, $class;
128 return $self;
129 }
130  
131 ##################
132 # Methods
133  
134 ##################
135 # Accessors - set
136  
137 sub set_enabledFlag {
138  
139 my ($self, $flag, $check) = @_;
140  
141 # Check for improper arguments
142 if (! defined $flag || defined $check) {
143  
144 return $axmud::CLIENT->writeImproper($self->_objClass . '->set_enabledFlag', @_);
145 }
146  
147 if ($flag) {
148 $self->ivPoke('enabledFlag', TRUE);
149 } else {
150 $self->ivPoke('enabledFlag', FALSE);
151 }
152  
153 return 1;
154 }
155  
156 ##################
157 # Accessors - get
158  
159 sub name
160 { $_[0]->{name} }
161 sub version
162 { $_[0]->{version} }
163 sub descrip
164 { $_[0]->{descrip} }
165 sub author
166 { $_[0]->{author} }
167 sub copyright
168 { $_[0]->{copyright} }
169 sub require
170 { $_[0]->{require} }
171 sub init
172 { $_[0]->{init} }
173  
174 sub filePath
175 { $_[0]->{filePath} }
176 sub enabledFlag
177 { $_[0]->{enabledFlag} }
178 }
179  
180 # Package must return a true value
181 1