lib/Games/Axmud.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/auto/share/dist/Games-Axmud/plugins/zmptest.pm ↑ Summary
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 # Lesser 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 # Lesser Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud
16 # All Perl objects used in Axmud should inherit this generic object, which serves as a base class
17 # for all Axmud objects and provides convenience functions for accessing scalar/array/hash
18 # instance variables (IVs) and for writing system messages
19 #
20 # Some Perl objects treat all of their IVs as 'public' - any of the methods inherited from this
21 # (base class) object can be called by other objects, in order to set IVs
22 # Other Perl objects treat all of their IVs as 'private' - other objects must call one of the
23 # specially-written accessor methods, in order to set its IVs
24 # All Perl objects have five special constant IVs: _objName, ->_objClass, _parentFile, _parentWorld
25 # and _privFlag. If _privFlag is set to TRUE, then an object's IVs are private. If set to FALSE,
26 # the object's IVs are public
27 #
28 # Some of the methods inherited from this object store value(s) in an IV, and some of them retrieve
29 # value(s) from an IV. Methods that retrieve values can be used all the time; methods that store
30 # values should only be used when an object's IVs are public, or when the object is modifying its
31 # own values
32 #
33 # Except in vary rare circumstances, you should not set an IV with a line of code like
34 # $obj->{some_iv} = $value
35 # ...because the code inherited from this object tells Axmud when its data has been modified, and
36 # needs to be saved
37 #
38 # The functions marked with an * are those which modify the value(s) of an instance variable (and so
39 # these are the ones which cause a file object's ->modifyFlag to be set to 1)
40 #
41 # ->checkModify($instVar) - Checks whether modifying an instance variable is allowed
42 #
43 # Functions for scalar IVs:
44 #
45 # ->ivSet($instVar, $value) * Set a scalar instance variable (IV)
46 # ->ivUndef($instVar) * Sets a scalar instance variable (IV) to 'undef'
47 # ->ivTrue($instVar) * Sets a scalar instance variable (IV) to TRUE
48 # ->ivFalse($instVar) * Sets a scalar instance variable (IV) to FALSE
49 # ->ivGet($instVar) - Get a scalar IV
50 # ->ivIncrement($instVar) * Incremements a scalar IV (i.e. $instVar++)
51 # ->ivDecrement($instVar) * Decrements a scalar IV (i.e. $instVar--)
52 # ->ivPlus($instVar, $value) * Performs addition on scalar IV (i.e. $instVar + $value)
53 # ->ivMinus($instVar, $value) * Performs subtraction on scalar IV (i.e. $instVar - $value)
54 # ->ivMultiply($instVar, $value)
55 # * Performs multiplication on scalar IV (i.e. $instVar * $value)
56 # ->ivDivide($instVar, $value)
57 # * Performs division on scalar IV (i.e. $instVar / $value)
58 # ->ivInt($instVar) * Remove the fractional part of an instance variable (IV)
59 #
60 # Functions for array IVs:
61 #
62 # ->ivPush($instVar, @list) * Push to an array IV
63 # ->ivPop($instVar) * Pop from an array IV
64 # ->ivUnshift($instVar, @list)
65 # * Unshift to an array IV
66 # ->ivShift($instVar) * Shift from an array IV
67 # ->ivNumber($instVar) - Number of elements in an array IV
68 # ->ivSplice($instVar, $offset, [$length, [@list]])
69 # * Splice an array IV
70 # ->ivIndex($instVar, $index) - Returns the element at the index in an array IV
71 # ->ivFirst($instVar) - Returns the element at index 0 in an array IV
72 # ->ivLast($instVar) - Returns the Last index (not the element) in an array IV
73 # ->ivReplace($instVar, $index, [$scalar])
74 # * Replaces the element at the index in an array IV
75 # ->ivFind($instVar, $scalar) - Finds the element in an array IV matching $scalar (string)
76 # ->ivMatch(instVar, $regEx, [$global, [$ignore]])
77 # - Finds the element in an array IV matching a Perl regex
78 # ->ivEquals($instVar, $number)
79 # - Finds the element in an array IV which equals $number
80 #
81 # Functions for hash IVs:
82 #
83 # ->ivAdd($instVar, $key, $value)
84 # * Adds a key-value pair to a hash IV
85 # ->ivIncHash($instVar, $key) * Increments the value of the key in a hash IV
86 # ->ivDecHash($instVar, $key) * Decrements the value of the key in a hash IV
87 # ->ivShow($instVar, $key) - Retrieves the value matching $key in a hash IV
88 # ->ivDelete($instVar, $key) * Deletes a key in a hash IV
89 # ->ivExists($instVar, $key) - Show if key exists in a hash IV
90 # ->ivKeys($instVar) - Gets list of all keys in a hash IV
91 # ->ivValues($instVar) - Gets list of all values in a hash IV
92 # ->ivPairs($instVar) - Returns number of key-value pairs in the hash IV
93 #
94 # Functions for scalar, array and hash IVs:
95 #
96 # ->ivList() - Retrieves list of all instance variables
97 # ->ivEmpty($instVar) * Empties an array or hash IV, sets a scalar IV to undef'
98 # ->ivType($instVar) - Returns the type of IV - 'scalar', 'list' or 'hash'
99 # ->ivPeek($instVar) - Returns the contents of an IV scalar, array or hash AS A LIST
100 # ->ivPoke($instVar, @list) * Sets the value of an IV scalar (identical to ->ivSet) to the first
101 # value in @list
102 # * Sets the contents of an IV list to @list, deleting any values
103 # already stored in the IV
104 # * Sets the contents of an IV hash to @list, deleting any key-value
105 # pairs already stored in the IV
106 # ->ivMember($instVar) - See if the IV exists in the object, or not
107 # ->ivCreate($instVar, $type) - Creates a new IV of $type 'scalar', 'list' or 'hash'
108 # ->ivDestroy($instVar) - Destroys an existing IV
109 #
110 # Other functions:
111 #
112 # ->writeText($text, @args) - Writes text to the a session's default textview object
113 # ->writeError($text, $func) - Writes an error message to a session's default textview object
114 # ->writeWarning($text, $func)
115 # - Writes a warning message to a session's default textview object
116 # ->writeDebug($text, $func) - Writes a debug message to a session's default textview object
117 # ->wd($text, $func) - Writes a debug message to a session's default textview object
118 # ->writeImproper($func, @args)
119 # - Writes an 'improper arguments' message to a session's default
120 # textview object
121 # ->debugBreak($title, $msg) - Show a 'dialogue' window, which pauses the script until the
122 # window is closed
123 # ->showList($lineNum, @list) - Debugging function, displays a list
124 # ->showHash($lineNum, %hash) - Debugging function, displays a hash
125 # ->getMethodRef($funcName) - Gets a reference to a function that's an OOP method
126  
127 { package Games::Axmud;
128  
129 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 # use diagnostics;
132  
133 # (This variable exists for the benefit of Kwalitee, and is never referenced by the code)
134 our $VERSION = '2.0.002';
135  
136 0 ▶ use Glib qw(TRUE FALSE);
Subroutine BEGIN: called CC=1 SCAR=2.6
137  
138 # our @ISA = qw();
139  
140 use Games::Axmud::Buffer;
141 use Games::Axmud::Cage;
142 use Games::Axmud::Client;
143 use Games::Axmud::Cmd;
144 use Games::Axmud::EditWin;
145 use Games::Axmud::FixedWin;
146 use Games::Axmud::Generic;
147 use Games::Axmud::Interface;
148 use Games::Axmud::InterfaceModel;
149 use Games::Axmud::Mcp;
150 use Games::Axmud::ModelObj;
151 use Games::Axmud::Mxp;
152 use Games::Axmud::Node;
153 use Games::Axmud::OtherWin;
154 use Games::Axmud::PrefWin;
155 use Games::Axmud::Profile;
156 use Games::Axmud::Pueblo;
157 use Games::Axmud::Session;
158 use Games::Axmud::Strip;
159 use Games::Axmud::Table;
160 use Games::Axmud::Task;
161 use Games::Axmud::WizWin;
162  
163 use Games::Axmud::Obj::Area;
164 use Games::Axmud::Obj::Atcp;
165 use Games::Axmud::Obj::BasicWorld;
166 use Games::Axmud::Obj::Blinker;
167 use Games::Axmud::Obj::ChatContact;
168 use Games::Axmud::Obj::ColourScheme;
169 use Games::Axmud::Obj::Component;
170 use Games::Axmud::Obj::ConnectHistory;
171 use Games::Axmud::Obj::Desktop;
172 use Games::Axmud::Obj::Dict;
173 use Games::Axmud::Obj::Exit;
174 use Games::Axmud::Obj::File;
175 use Games::Axmud::Obj::Gauge;
176 use Games::Axmud::Obj::GaugeLevel;
177 use Games::Axmud::Obj::Gmcp;
178 use Games::Axmud::Obj::GridColour;
179 use Games::Axmud::Obj::Heap;
180 use Games::Axmud::Obj::Link;
181 use Games::Axmud::Obj::Loop;
182 use Games::Axmud::Obj::Map;
183 use Games::Axmud::Obj::MapLabel;
184 use Games::Axmud::Obj::MiniWorld;
185 use Games::Axmud::Obj::Mission;
186 use Games::Axmud::Obj::Monitor;
187 use Games::Axmud::Obj::Parchment;
188 use Games::Axmud::Obj::Phrasebook;
189 use Games::Axmud::Obj::Plugin;
190 use Games::Axmud::Obj::Protect;
191 use Games::Axmud::Obj::Quest;
192 use Games::Axmud::Obj::RegionScheme;
193 use Games::Axmud::Obj::Regionmap;
194 use Games::Axmud::Obj::RegionPath;
195 use Games::Axmud::Obj::Repeat;
196 use Games::Axmud::Obj::RoomFlag;
197 use Games::Axmud::Obj::Route;
198 use Games::Axmud::Obj::Simple;
199 use Games::Axmud::Obj::SkillHistory;
200 use Games::Axmud::Obj::Sound;
201 use Games::Axmud::Obj::Tab;
202 use Games::Axmud::Obj::Tablezone;
203 use Games::Axmud::Obj::Telnet;
204 use Games::Axmud::Obj::TextView;
205 use Games::Axmud::Obj::Toolbar;
206 use Games::Axmud::Obj::Tts;
207 use Games::Axmud::Obj::Winmap;
208 use Games::Axmud::Obj::Winzone;
209 use Games::Axmud::Obj::WMCtrl;
210 use Games::Axmud::Obj::Workspace;
211 use Games::Axmud::Obj::WorkspaceGrid;
212 use Games::Axmud::Obj::WorldModel;
213 use Games::Axmud::Obj::Zmp;
214 use Games::Axmud::Obj::Zone;
215 use Games::Axmud::Obj::Zonemap;
216 use Games::Axmud::Obj::ZoneModel;
217  
218 use Games::Axmud::Win::External;
219 use Games::Axmud::Win::Internal;
220 use Games::Axmud::Win::Map;
221  
222 ##################
223 # Constructors
224  
225 # (All inheriting objects must provide their own ->new function)
226  
227 ##################
228 # Methods
229  
230 # General methods
231  
232 sub checkModify {
233  
234 # Can be called by any of the ->ivXXX methods in this object which modify the value(s)
235 # stored in the object's IVs
236 # Given the instance variable to be modified, checks whether modifying this variable is
237 # allowed. (It's up to the Axmud code to refrain from modifying IVs in other Perl objects,
238 # when those objects have their ->_privFlag set to TRUE)
239 #
240 # Expected arguments
241 # $iv - The instance variable to be modified
242 #
243 # Return values
244 # 'undef' on improper arguments, or if modifying the IV is not allowed
245 # 1 on success
246  
247 my ($self, $iv, $check) = @_;
248  
249 # Check for improper arguments
250 if (! defined $iv || defined $check) {
251  
252 return $axmud::CLIENT->writeImproper($self->_objClass . '->checkModify', @_);
253 }
254  
255 # Check whether modifying this instance variable is allowed
256  
257 if ($axmud::CLIENT->ivExists('constIVHash', $iv)) {
258  
259 # This is a constant instance variable (i.e. '_objName', '_objClass', '_parentFile',
260 # '_parentWorld', or '_privFlag') required by the system
261 return $axmud::CLIENT->writeError(
262 '\'' . $iv . '\' is a system constant IV which must not be modified',
263 $self->_objClass . '->checkModify',
264 );
265  
266 } elsif (substr ($iv, 0, 5) eq 'const') {
267  
268 # This is a constant Axmud instance variable. ->iv functions can't be used to modify it
269 return $axmud::CLIENT->writeError(
270 '\'' . $iv . '\' is a constant IV which cannot be modified',
271 $self->_objClass . '->checkModify',
272 );
273  
274 } else {
275  
276 # Modification of this IV is allowed
277 return 1;
278 }
279 }
280  
281 sub doModify {
282  
283 # Can be called by any of the ->ivXXX methods in this object after a call to
284 # $self->checkModify
285 # If there is a parent file object stored in $self->_parentFile, sets its ->modifyFlag to
286 # TRUE
287 #
288 # Expected arguments
289 # $func - The calling function (e.g. 'ivPoke')
290 #
291 # Return values
292 # 'undef' on improper arguments
293 # 1 on success
294  
295 my ($self, $func, $check) = @_;
296  
297 # Check for improper arguments
298 if (! defined $func || defined $check) {
299  
300 return $axmud::CLIENT->writeImproper($self->_objClass . '->doModify', @_);
301 }
302  
303 # Set the parent file's 'data modified' flag
304 if (defined $self->_parentFile) {
305  
306 # (For some task objects, $self->session is defined, for others, it is not)
307 if (exists $self->{session} && defined $self->{session}) {
308  
309 # The parent file object is stored either in GA::Client or in this GA::Session.
310 # Call the GA::Session; if it doesn't store the file object, it passes on the call
311 # to the GA::Client
312 $self->session->setModifyFlag(
313 $self->_parentFile,
314 TRUE,
315 $self->_objClass . '->' . $func,
316 );
317  
318 } elsif (defined $self->_parentWorld) {
319  
320 # The parent file object is not stored in GA::Client, but in a GA::Session, but we
321 # don't know which session (because there is no ->session IV)
322 # Check each session in turn, looking for the right file object. As soon as it is
323 # found, set the flag
324 OUTER: foreach my $session ($axmud::CLIENT->listSessions()) {
325  
326 if (
327 $session->currentWorld
328 && $session->currentWorld->name eq $self->_parentWorld
329 ) {
330 # This is the right sesion
331 $session->setModifyFlag(
332 $self->_parentFile,
333 TRUE,
334 $self->_objClass . '->' . $func,
335 );
336  
337 last OUTER;
338 }
339 }
340  
341 } else {
342  
343 # Most file objects are stored in the GA::Client
344 $axmud::CLIENT->setModifyFlag(
345 $self->_parentFile,
346 TRUE,
347 $self->_objClass . '->' . $func,
348 );
349 }
350 }
351  
352 return 1;
353 }
354  
355 # IV methods
356  
357 sub ivSet {
358  
359 # Set variable function for scalar instance variables
360 #
361 # Expected arguments
362 # $iv - Which scalar instance variable to modify
363 # $value - What the instance variable is set to
364 #
365 # Return values
366 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
367 # supplied)
368 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->regConst) or
369 # or if it begins with _, meaning modification not allowed using this function
370 # 1 on success
371  
372 my ($self, $iv, $value, $check) = @_;
373  
374 # Local variables
375 my $refType;
376  
377 # Check for improper arguments
378 if (! defined $iv || ! defined $value || defined $check) {
379  
380 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivSet', @_);
381 }
382  
383 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
384 # exist, initialise it using a default value from the default object stored in a global
385 # variable)
386 if (! exists $self->{$iv}) {
387  
388 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
389 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
390 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
391 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
392 } else {
393  
394 if ($axmud::CLIENT->debugCheckIVFlag) {
395  
396 $self->writeDebug(
397 'Code accessed non-existent IV \'' . $iv . '\'',
398 $self->_objClass . '->ivSet',
399 );
400 }
401  
402 return undef;
403 }
404 }
405  
406 # Check that modifying the instance variable is allowed
407 if (! $self->checkModify($iv)) {
408  
409 return undef;
410 }
411  
412 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
413 # a scalar instance variable; so treat it as a scalar
414 $refType = ref $self->{$iv};
415 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
416  
417 # This is a scalar. Set the parent file object's 'data modified' flag
418 $self->doModify('ivSet');
419  
420 # Set the scalar
421 $self->{$iv} = $value;
422  
423 return 1;
424  
425 } else {
426  
427 # Not a scalar
428 return undef;
429 }
430 }
431  
432 sub ivUndef {
433  
434 # Set variable to 'undef' function for scalar instance variables
435 #
436 # Expected arguments
437 # $iv - Which scalar instance variable to modify
438 #
439 # Return values
440 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
441 # supplied)
442 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
443 # or if it begins with _, meaning modification not allowed using this function
444 # 1 on success
445  
446 my ($self, $iv, $check) = @_;
447  
448 # Local variables
449 my $refType;
450  
451 # Check for improper arguments
452 if (! defined $iv || defined $check) {
453  
454 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivUndef', @_);
455 }
456  
457 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
458 # exist, initialise it using a default value from the default object stored in a global
459 # variable)
460 if (! exists $self->{$iv}) {
461  
462 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
463 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
464 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
465 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
466 } else {
467  
468 if ($axmud::CLIENT->debugCheckIVFlag) {
469  
470 $self->writeDebug(
471 'Code accessed non-existent IV \'' . $iv . '\'',
472 $self->_objClass . '->ivUndef',
473 );
474 }
475  
476 return undef;
477 }
478 }
479  
480 # Check that modifying the instance variable is allowed
481 if (! $self->checkModify($iv)) {
482  
483 return undef;
484 }
485  
486 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
487 # a scalar instance variable; so treat it as a scalar
488 $refType = ref $self->{$iv};
489 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
490  
491 # This is a scalar. Set the parent file object's 'data modified' flag
492 $self->doModify('ivUndef');
493  
494 # Set the scalar
495 $self->{$iv} = undef;
496  
497 return 1;
498  
499 } else {
500  
501 # Not a scalar
502 return undef;
503 }
504 }
505  
506 sub ivTrue {
507  
508 # Set variable to TRUE function for scalar instance variables
509 #
510 # Expected arguments
511 # $iv - Which scalar instance variable to modify
512 #
513 # Return values
514 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
515 # supplied)
516 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
517 # or if it begins with _, meaning modification not allowed using this function
518 # 1 on success
519  
520 my ($self, $iv, $check) = @_;
521  
522 # Local variables
523 my $refType;
524  
525 # Check for improper arguments
526 if (! defined $iv || defined $check) {
527  
528 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivTrue', @_);
529 }
530  
531 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
532 # exist, initialise it using a default value from the default object stored in a global
533 # variable)
534 if (! exists $self->{$iv}) {
535  
536 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
537 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
538 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
539 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
540 } else {
541  
542 if ($axmud::CLIENT->debugCheckIVFlag) {
543  
544 $self->writeDebug(
545 'Code accessed non-existent IV \'' . $iv . '\'',
546 $self->_objClass . '->ivTrue',
547 );
548 }
549  
550 return undef;
551 }
552 }
553  
554 # Check that modifying the instance variable is allowed
555 if (! $self->checkModify($iv)) {
556  
557 return undef;
558 }
559  
560 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
561 # a scalar instance variable; so treat it as a scalar
562 $refType = ref $self->{$iv};
563 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
564  
565 # This is a scalar. Set the parent file object's 'data modified' flag
566 $self->doModify('ivTrue');
567  
568 # Set the scalar
569 $self->{$iv} = TRUE;
570  
571 return 1;
572  
573 } else {
574  
575 # Not a scalar
576 return undef;
577 }
578 }
579  
580 sub ivFalse {
581  
582 # Set variable to FALSE function for scalar instance variables
583 #
584 # Expected arguments
585 # $iv - Which scalar instance variable to modify
586 #
587 # Return values
588 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
589 # supplied)
590 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
591 # or if it begins with _, meaning modification not allowed using this function
592 # 1 on success
593  
594 my ($self, $iv, $check) = @_;
595  
596 # Local variables
597 my $refType;
598  
599 # Check for improper arguments
600 if (! defined $iv || defined $check) {
601  
602 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivFalse', @_);
603 }
604  
605 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
606 # exist, initialise it using a default value from the default object stored in a global
607 # variable)
608 if (! exists $self->{$iv}) {
609  
610 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
611 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
612 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
613 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
614 } else {
615  
616 if ($axmud::CLIENT->debugCheckIVFlag) {
617  
618 $self->writeDebug(
619 'Code accessed non-existent IV \'' . $iv . '\'',
620 $self->_objClass . '->ivFalse',
621 );
622 }
623  
624 return undef;
625 }
626 }
627  
628 # Check that modifying the instance variable is allowed
629 if (! $self->checkModify($iv)) {
630  
631 return undef;
632 }
633  
634 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
635 # a scalar instance variable; so treat it as a scalar
636 $refType = ref $self->{$iv};
637 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
638  
639 # This is a scalar. Set the parent file object's 'data modified' flag
640 $self->doModify('ivFalse');
641  
642 # Set the scalar
643 $self->{$iv} = FALSE;
644  
645 return 1;
646  
647 } else {
648  
649 # Not a scalar
650 return undef;
651 }
652 }
653  
654 sub ivGet {
655  
656 # Retrieve variable function for scalar instance variables
657 #
658 # Expected arguments
659 # $iv - Which scalar instance variable to get
660 #
661 # Return values
662 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
663 # supplied)
664 # The instance variable's value on success
665  
666 my ($self, $iv, $check) = @_;
667  
668 # Local variables
669 my $refType;
670  
671 # Check for improper arguments
672 if (! defined $iv || defined $check) {
673  
674 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivGet', @_);
675 }
676  
677 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
678 # exist, get a default value from the default object stored in a global variable)
679 if (! exists $self->{$iv}) {
680  
681 if ($self->isa('Games::Axmud::ModelObj::Room')) {
682 $self = $axmud::DEFAULT_ROOM;
683 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
684 $self = $axmud::DEFAULT_EXIT;
685 }
686  
687 if (! exists $self->{$iv}) {
688  
689 if ($axmud::CLIENT->debugCheckIVFlag) {
690  
691 $self->writeDebug(
692 'Code accessed non-existent IV \'' . $iv . '\'',
693 $self->_objClass . '->ivGet',
694 );
695 }
696  
697 return undef;
698 }
699 }
700  
701 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
702 # a scalar instance variable; so treat it as a scalar
703 $refType = ref $self->{$iv};
704 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
705  
706 # This is a scalar. Retrieve its value
707 return $self->{$iv};
708  
709 } else {
710  
711 # Not a scalar
712 return undef;
713 }
714 }
715  
716 sub ivIncrement {
717  
718 # Increments a scalar instance variable by 1
719 #
720 # Expected arguments
721 # $iv - Which scalar instance variable to modify
722 #
723 # Return values
724 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
725 # supplied)
726 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
727 # or if it begins with _, meaning modification not allowed using this function
728 # The instance variable's value on success
729  
730 my ($self, $iv, $check) = @_;
731  
732 # Local variables
733 my $refType;
734  
735 # Check for improper arguments
736 if (! defined $iv || defined $check) {
737  
738 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivIncrement', @_);
739 }
740  
741 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
742 # exist, initialise it using a default value from the default object stored in a global
743 # variable)
744 if (! exists $self->{$iv}) {
745  
746 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
747 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
748 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
749 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
750 } else {
751  
752 if ($axmud::CLIENT->debugCheckIVFlag) {
753  
754 $self->writeDebug(
755 'Code accessed non-existent IV \'' . $iv . '\'',
756 $self->_objClass . '->ivIncrement',
757 );
758 }
759  
760 return undef;
761 }
762 }
763  
764 # Check that modifying the instance variable is allowed
765 if (! $self->checkModify($iv)) {
766  
767 return undef;
768 }
769  
770 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
771 # a scalar instance variable; so treat it as a scalar
772 $refType = ref $self->{$iv};
773 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
774  
775 # This is a scalar. Set the parent file object's 'data modified' flag
776 $self->doModify('ivIncrement');
777  
778 # Increment the scalar and return it
779 return ++($self->{$iv});
780  
781 } else {
782  
783 # Not a scalar
784 return undef;
785 }
786 }
787  
788 sub ivDecrement {
789  
790 # Decrements a scalar instance variable by 1
791 #
792 # Expected arguments
793 # $iv - Which scalar instance variable to modify
794 #
795 # Return values
796 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
797 # supplied)
798 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
799 # or if it begins with _, meaning modification not allowed using this function
800 # The instance variable's value on success
801  
802 my ($self, $iv, $check) = @_;
803  
804 # Local variables
805 my $refType;
806  
807 # Check for improper arguments
808 if (! defined $iv || defined $check) {
809  
810 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivDecrement', @_);
811 }
812  
813 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
814 # exist, initialise it using a default value from the default object stored in a global
815 # variable)
816 if (! exists $self->{$iv}) {
817  
818 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
819 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
820 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
821 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
822 } else {
823  
824 if ($axmud::CLIENT->debugCheckIVFlag) {
825  
826 $self->writeDebug(
827 'Code accessed non-existent IV \'' . $iv . '\'',
828 $self->_objClass . '->ivDecrement',
829 );
830 }
831  
832 return undef;
833 }
834 }
835  
836 # Check that modifying the instance variable is allowed
837 if (! $self->checkModify($iv)) {
838  
839 return undef;
840 }
841  
842 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
843 # a scalar instance variable; so treat it as a scalar
844 $refType = ref $self->{$iv};
845 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
846  
847 # This is a scalar. Set the parent file object's 'data modified' flag
848 $self->doModify('ivDecrement');
849  
850 # Decrement the scalar and return it
851 return --($self->{$iv});
852  
853 } else {
854  
855 # Not a scalar
856 return undef;
857 }
858 }
859  
860 sub ivPlus {
861  
862 # Performs an addition operation on a scalar instance variable
863 #
864 # Expected arguments
865 # $iv - Which scalar instance variable to modify
866 # $value - Which value to add
867 #
868 # Return values
869 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
870 # supplied)
871 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
872 # or if it begins with _, meaning modification not allowed using this function
873 # The instance variable's value on success ($self->instanceVariable + $value)
874  
875 my ($self, $iv, $value, $check) = @_;
876  
877 # Local variables
878 my $refType;
879  
880 # Check for improper arguments
881 if (! defined $iv || ! defined $value || defined $check) {
882  
883 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivPlus', @_);
884 }
885  
886 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
887 # exist, initialise it using a default value from the default object stored in a global
888 # variable)
889 if (! exists $self->{$iv}) {
890  
891 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
892 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
893 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
894 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
895 } else {
896  
897 if ($axmud::CLIENT->debugCheckIVFlag) {
898  
899 $self->writeDebug(
900 'Code accessed non-existent IV \'' . $iv . '\'',
901 $self->_objClass . '->ivPlus',
902 );
903 }
904  
905 return undef;
906 }
907 }
908  
909 # Check that modifying the instance variable is allowed
910 if (! $self->checkModify($iv)) {
911  
912 return undef;
913 }
914  
915 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
916 # a scalar instance variable; so treat it as a scalar
917 $refType = ref $self->{$iv};
918 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
919  
920 # This is a scalar. Set the parent file object's 'data modified' flag
921 $self->doModify('ivPlus');
922  
923 # Perform the addition
924 $self->{$iv} += $value;
925 return $self->{$iv};
926  
927 } else {
928  
929 # Not a scalar
930 return undef;
931 }
932 }
933  
934 sub ivMinus {
935  
936 # Performs a subtraction operation on a scalar instance variable
937 #
938 # Expected arguments
939 # $iv - Which scalar instance variable to modify
940 # $value - Which value to subtract
941 #
942 # Return values
943 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
944 # supplied)
945 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
946 # or if it begins with _, meaning modification not allowed using this function
947 # The instance variable's value on success ($self->instanceVariable - $value)
948  
949 my ($self, $iv, $value, $check) = @_;
950  
951 # Local variables
952 my $refType;
953  
954 # Check for improper arguments
955 if (! defined $iv || ! defined $value || defined $check) {
956  
957 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivMinus', @_);
958 }
959  
960 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
961 # exist, initialise it using a default value from the default object stored in a global
962 # variable)
963 if (! exists $self->{$iv}) {
964  
965 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
966 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
967 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
968 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
969 } else {
970  
971 if ($axmud::CLIENT->debugCheckIVFlag) {
972  
973 $self->writeDebug(
974 'Code accessed non-existent IV \'' . $iv . '\'',
975 $self->_objClass . '->ivMinus',
976 );
977 }
978  
979 return undef;
980 }
981 }
982  
983 # Check that modifying the instance variable is allowed
984 if (! $self->checkModify($iv)) {
985  
986 return undef;
987 }
988  
989 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
990 # a scalar instance variable; so treat it as a scalar
991 $refType = ref $self->{$iv};
992 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
993  
994 # This is a scalar. Set the parent file object's 'data modified' flag
995 $self->doModify('ivMinus');
996  
997 # Perform the subtraction
998 $self->{$iv} -= $value;
999  
1000 return $self->{$iv};
1001  
1002 } else {
1003  
1004 # Not a scalar
1005 return undef;
1006 }
1007 }
1008  
1009 sub ivMultiply {
1010  
1011 # Performs a multiplication operation on a scalar instance variable
1012 #
1013 # Expected arguments
1014 # $iv - Which scalar instance variable to modify
1015 # $value - Which value to multiply with
1016 #
1017 # Return values
1018 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
1019 # supplied)
1020 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1021 # or if it begins with _, meaning modification not allowed using this function
1022 # The instance variable's value on success ($self->instanceVariable * $value)
1023  
1024 my ($self, $iv, $value, $check) = @_;
1025  
1026 # Local variables
1027 my $refType;
1028  
1029 # Check for improper arguments
1030 if (! defined $iv || ! defined $value || defined $check) {
1031  
1032 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivMultiply', @_);
1033 }
1034  
1035 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1036 # exist, initialise it using a default value from the default object stored in a global
1037 # variable)
1038 if (! exists $self->{$iv}) {
1039  
1040 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1041 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
1042 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1043 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
1044 } else {
1045  
1046 if ($axmud::CLIENT->debugCheckIVFlag) {
1047  
1048 $self->writeDebug(
1049 'Code accessed non-existent IV \'' . $iv . '\'',
1050 $self->_objClass . '->ivMultiply',
1051 );
1052 }
1053  
1054 return undef;
1055 }
1056 }
1057  
1058 # Check that modifying the instance variable is allowed
1059 if (! $self->checkModify($iv)) {
1060  
1061 return undef;
1062 }
1063  
1064 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
1065 # a scalar instance variable; so treat it as a scalar
1066 $refType = ref $self->{$iv};
1067 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
1068  
1069 # This is a scalar. Set the parent file object's 'data modified' flag
1070 $self->doModify('ivMultiply');
1071  
1072 # Perform the multiplication
1073 $self->{$iv} *= $value;
1074  
1075 return $self->{$iv};
1076  
1077 } else {
1078  
1079 # Not a scalar
1080 return undef;
1081 }
1082 }
1083  
1084 sub ivDivide {
1085  
1086 # Performs a division operation on a scalar instance variable
1087 #
1088 # Expected arguments
1089 # $iv - Which scalar instance variable to modify
1090 # $value - Which value to divide by
1091 #
1092 # Return values
1093 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
1094 # supplied)
1095 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1096 # or if it begins with _, meaning modification not allowed using this function
1097 # The instance variable's value on success ($self->instanceVariable / $value)
1098  
1099 my ($self, $iv, $value, $check) = @_;
1100  
1101 # Local variables
1102 my $refType;
1103  
1104 # Check for improper arguments
1105 if (! defined $iv || ! defined $value || defined $check) {
1106  
1107 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivDivide', @_);
1108 }
1109  
1110 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1111 # exist, initialise it using a default value from the default object stored in a global
1112 # variable)
1113 if (! exists $self->{$iv}) {
1114  
1115 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1116 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
1117 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1118 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
1119 } else {
1120  
1121 if ($axmud::CLIENT->debugCheckIVFlag) {
1122  
1123 $self->writeDebug(
1124 'Code accessed non-existent IV \'' . $iv . '\'',
1125 $self->_objClass . '->ivDivide',
1126 );
1127 }
1128  
1129 return undef;
1130 }
1131 }
1132  
1133 # Check that modifying the instance variable is allowed
1134 if (! $self->checkModify($iv)) {
1135  
1136 return undef;
1137 }
1138  
1139 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
1140 # a scalar instance variable; so treat it as a scalar
1141 $refType = ref $self->{$iv};
1142 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
1143  
1144 # This is a scalar. Set the parent file object's 'data modified' flag
1145 $self->doModify('ivDivide');
1146  
1147 # Perform the division
1148 $self->{$iv} /= $value;
1149  
1150 return $self->{$iv};
1151  
1152 } else {
1153  
1154 # Not a scalar
1155 return undef;
1156 }
1157 }
1158  
1159 sub ivInt {
1160  
1161 # Removes the fractional part of an instance variable
1162 #
1163 # Expected arguments
1164 # $iv - Which scalar instance variable to modify
1165 #
1166 # Return values
1167 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar, or improper arguments
1168 # supplied)
1169 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1170 # or if it begins with _, meaning modification not allowed using this function
1171 # The instance variable's value on success
1172  
1173 my ($self, $iv, $check) = @_;
1174  
1175 # Local variables
1176 my $refType;
1177  
1178 # Check for improper arguments
1179 if (! defined $iv || defined $check) {
1180  
1181 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivInt', @_);
1182 }
1183  
1184 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1185 # exist, initialise it using a default value from the default object stored in a global
1186 # variable)
1187 if (! exists $self->{$iv}) {
1188  
1189 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1190 $self->{$iv} = $axmud::DEFAULT_ROOM->{$iv};
1191 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1192 $self->{$iv} = $axmud::DEFAULT_EXIT->{$iv};
1193 } else {
1194  
1195 if ($axmud::CLIENT->debugCheckIVFlag) {
1196  
1197 $self->writeDebug(
1198 'Code accessed non-existent IV \'' . $iv . '\'',
1199 $self->_objClass . '->ivInt',
1200 );
1201 }
1202  
1203 return undef;
1204 }
1205 }
1206  
1207 # Check that modifying the instance variable is allowed
1208 if (! $self->checkModify($iv)) {
1209  
1210 return undef;
1211 }
1212  
1213 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
1214 # a scalar instance variable; so treat it as a scalar
1215 $refType = ref $self->{$iv};
1216 if ($refType ne 'ARRAY' && $refType ne 'HASH') {
1217  
1218 # This is a scalar. Set the parent file object's 'data modified' flag
1219 $self->doModify('ivInt');
1220  
1221 # Increment the scalar and return it
1222 return $self->{$iv} = int($self->{$iv});
1223  
1224 } else {
1225  
1226 # Not a scalar
1227 return undef;
1228 }
1229 }
1230  
1231 sub ivPush {
1232  
1233 # Push function for array instance variables
1234 #
1235 # Expected arguments
1236 # $iv - Which array instance variable to modify
1237 #
1238 # Optional arguments
1239 # @list - List of values to push into the array (can be an empty list)
1240 #
1241 # Return values
1242 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1243 # supplied)
1244 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1245 # or if it begins with _, meaning modification not allowed using this function
1246 # 1 on success
1247  
1248 my ($self, $iv, @list) = @_;
1249  
1250 # Local variables
1251 my ($varRef, $refType);
1252  
1253 # Check for improper arguments
1254 if (! defined $iv) {
1255  
1256 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivPush', @_);
1257 }
1258  
1259 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1260 # exist, initialise it using a default value from the default object stored in a global
1261 # variable)
1262 if (! exists $self->{$iv}) {
1263  
1264 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1265  
1266 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1267 $self->{$iv} = $varRef;
1268  
1269 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1270  
1271 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1272 $self->{$iv} = $varRef;
1273  
1274 } else {
1275  
1276 if ($axmud::CLIENT->debugCheckIVFlag) {
1277  
1278 $self->writeDebug(
1279 'Code accessed non-existent IV \'' . $iv . '\'',
1280 $self->_objClass . '->ivPush',
1281 );
1282 }
1283  
1284 return undef;
1285 }
1286 }
1287  
1288 # Check that modifying the instance variable is allowed
1289 if (! $self->checkModify($iv)) {
1290  
1291 return undef;
1292 }
1293  
1294 $refType = ref $self->{$iv};
1295 if ($refType eq 'ARRAY') {
1296  
1297 # This is a list. Set the parent file object's 'data modified' flag
1298 $self->doModify('ivPush');
1299  
1300 # Perform the push operation
1301 push( @{$self->{$iv}}, @list );
1302  
1303 return 1;
1304  
1305 } else {
1306  
1307 # Not a list
1308 return undef;
1309 }
1310 }
1311  
1312 sub ivPop {
1313  
1314 # Pop function for array instance variables
1315 #
1316 # Expected arguments
1317 # $iv - Which array instance variable to modify
1318 #
1319 # Return values
1320 # 'undef' on failure (because $iv doesn't exist, or isn't an arry, or improper arguments
1321 # supplied)
1322 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1323 # or if it begins with _, meaning modification not allowed using this function
1324 # A scalar value on success
1325  
1326 my ($self, $iv, $check) = @_;
1327  
1328 # Local variables
1329 my ($varRef, $refType, $returnValue);
1330  
1331 # Check for improper arguments
1332 if (! defined $iv || defined $check) {
1333  
1334 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivPop', @_);
1335 }
1336  
1337 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1338 # exist, initialise it using a default value from the default object stored in a global
1339 # variable)
1340 if (! exists $self->{$iv}) {
1341  
1342 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1343  
1344 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1345 $self->{$iv} = $varRef;
1346  
1347 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1348  
1349 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1350 $self->{$iv} = $varRef;
1351  
1352 } else {
1353  
1354 if ($axmud::CLIENT->debugCheckIVFlag) {
1355  
1356 $self->writeDebug(
1357 'Code accessed non-existent IV \'' . $iv . '\'',
1358 $self->_objClass . '->ivPop',
1359 );
1360 }
1361  
1362 return undef;
1363 }
1364 }
1365  
1366 # Check that modifying the instance variable is allowed
1367 if (! $self->checkModify($iv)) {
1368  
1369 return undef;
1370 }
1371  
1372 $refType = ref $self->{$iv};
1373 if ($refType eq 'ARRAY') {
1374  
1375 # This is a list. Set the parent file object's 'data modified' flag
1376 $self->doModify('ivPop');
1377  
1378 # Perform the pop operation
1379 return ( pop @{$self->{$iv}} );
1380  
1381 } else {
1382  
1383 # Not a list
1384 return undef;
1385 }
1386 }
1387  
1388 sub ivUnshift {
1389  
1390 # Unshift function for array instance variables
1391 #
1392 # Expected arguments
1393 # $iv - Which array instance variable to modify
1394 #
1395 # Optional arguments
1396 # @list - List of values to unshift into the array (can be an empty list)
1397 #
1398 # Return values
1399 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1400 # supplied)
1401 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1402 # or if it begins with _, meaning modification not allowed using this function
1403 # Number of elements in new array, on success
1404  
1405 my ($self, $iv, @list) = @_;
1406  
1407 # Local variables
1408 my ($varRef, $refType);
1409  
1410 # Check for improper arguments
1411 if (! defined $iv) {
1412  
1413 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivUnshift', @_);
1414 }
1415  
1416 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1417 # exist, initialise it using a default value from the default object stored in a global
1418 # variable)
1419 if (! exists $self->{$iv}) {
1420  
1421 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1422  
1423 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1424 $self->{$iv} = $varRef;
1425  
1426 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1427  
1428 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1429 $self->{$iv} = $varRef;
1430  
1431 } else {
1432  
1433 if ($axmud::CLIENT->debugCheckIVFlag) {
1434  
1435 $self->writeDebug(
1436 'Code accessed non-existent IV \'' . $iv . '\'',
1437 $self->_objClass . '->ivUnshift',
1438 );
1439 }
1440  
1441 return undef;
1442 }
1443 }
1444  
1445 # Check that modifying the instance variable is allowed
1446 if (! $self->checkModify($iv)) {
1447  
1448 return undef;
1449 }
1450  
1451 $refType = ref $self->{$iv};
1452 if ($refType eq 'ARRAY') {
1453  
1454 # This is a list. Set the parent file object's 'data modified' flag
1455 $self->doModify('ivUnshift');
1456  
1457 # Perform the unshift operation
1458 return ( unshift(@{$self->{$iv}}, @list) );
1459  
1460 } else {
1461  
1462 # Not a list
1463 return undef;
1464 }
1465 }
1466  
1467 sub ivShift {
1468  
1469 # Shift function for array instance variables
1470 #
1471 # Expected arguments
1472 # $iv - Which array instance variable to modify
1473 #
1474 # Return values
1475 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1476 # supplied)
1477 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1478 # or if it begins with _, meaning modification not allowed using this function
1479 # A scalar value on success
1480  
1481 my ($self, $iv, $check) = @_;
1482  
1483 # Local variables
1484 my ($varRef, $refType, $returnValue);
1485  
1486 # Check for improper arguments
1487 if (! defined $iv || defined $check) {
1488  
1489 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivSet', @_);
1490 }
1491  
1492 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1493 # exist, initialise it using a default value from the default object stored in a global
1494 # variable)
1495 if (! exists $self->{$iv}) {
1496  
1497 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1498  
1499 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1500 $self->{$iv} = $varRef;
1501  
1502 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1503  
1504 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1505 $self->{$iv} = $varRef;
1506  
1507 } else {
1508  
1509 if ($axmud::CLIENT->debugCheckIVFlag) {
1510  
1511 $self->writeDebug(
1512 'Code accessed non-existent IV \'' . $iv . '\'',
1513 $self->_objClass . '->ivShift',
1514 );
1515 }
1516  
1517 return undef;
1518 }
1519 }
1520  
1521 # Check that modifying the instance variable is allowed
1522 if (! $self->checkModify($iv)) {
1523  
1524 return undef;
1525 }
1526  
1527 $refType = ref $self->{$iv};
1528 if ($refType eq 'ARRAY') {
1529  
1530 # This is a list. Set the parent file object's 'data modified' flag
1531 $self->doModify('ivShift');
1532  
1533 # Perform the shift operation
1534 return ( shift @{$self->{$iv}} );
1535  
1536 } else {
1537  
1538 # Not a list
1539 return undef;
1540 }
1541 }
1542  
1543 sub ivNumber {
1544  
1545 # Function to retrieve the number of elements in an array instance variable
1546 #
1547 # Expected arguments
1548 # $iv - Which array instance variable to check
1549 #
1550 # Return values
1551 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1552 # supplied)
1553 # An integer upon success (which might be 0 if the array is empty)
1554  
1555 my ($self, $iv, $check) = @_;
1556  
1557 # Local variables
1558 my $refType;
1559  
1560 # Check for improper arguments
1561 if (! defined $iv || defined $check) {
1562  
1563 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivNumber', @_);
1564 }
1565  
1566 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1567 # exist, get a default value from the default object stored in a global variable)
1568 if (! exists $self->{$iv}) {
1569  
1570 if ($self->isa('Games::Axmud::ModelObj::Room')) {
1571 $self = $axmud::DEFAULT_ROOM;
1572 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
1573 $self = $axmud::DEFAULT_EXIT;
1574 }
1575  
1576 if (! exists $self->{$iv}) {
1577  
1578 if ($axmud::CLIENT->debugCheckIVFlag) {
1579  
1580 $self->writeDebug(
1581 'Code accessed non-existent IV \'' . $iv . '\'',
1582 $self->_objClass . '->ivNumber'
1583 );
1584 }
1585  
1586 return undef;
1587 }
1588 }
1589  
1590 $refType = ref $self->{$iv};
1591 if ($refType eq 'ARRAY') {
1592  
1593 # This is a list. Return the number of elements
1594 return (scalar @{$self->{$iv}});
1595  
1596 } else {
1597  
1598 # Not a list
1599 return undef;
1600 }
1601 }
1602  
1603 sub ivSplice {
1604  
1605 # Function to splice an array instance variable. Returns the spliced elements (obeys the
1606 # same rules as the Perl splice() function)
1607 #
1608 # Expected arguments
1609 # $iv - Which array instance variable to splice
1610 # $offset - Which index at which to start removing elements
1611 #
1612 # Optional arguments
1613 # $length - How many elements to remove (default is all elements from $offset onwards)
1614 # @list - List of scalars to insert at the splice
1615 #
1616 # Return values
1617 # An empty list on failure (because $iv doesn't exist, or isn't an array, or improper
1618 # arguments supplied)
1619 # An empty list if $iv is a system constant (specified by the keys in
1620 # GA::Client->constIVHash) or or if it begins with _, meaning modification not allowed
1621 # using this function
1622 # Returns @returnArray, the list of elements removed from the array, on success
1623  
1624 my ($self, $iv, $offset, $length, @list) = @_;
1625  
1626 # Local variables
1627 my (
1628 $varRef, $refType,
1629 @emptyList, @returnArray,
1630 );
1631  
1632 # Check for improper arguments
1633 if (! defined $iv || ! defined $offset) {
1634  
1635 $axmud::CLIENT->writeImproper($self->_objClass . '->ivSplice', @_);
1636 return @emptyList;
1637 }
1638  
1639 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1640 # exist, initialise it using a default value from the default object stored in a global
1641 # variable)
1642 if (! exists $self->{$iv}) {
1643  
1644 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1645  
1646 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1647 $self->{$iv} = $varRef;
1648  
1649 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1650  
1651 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1652 $self->{$iv} = $varRef;
1653  
1654 } else {
1655  
1656 if ($axmud::CLIENT->debugCheckIVFlag) {
1657  
1658 $self->writeDebug(
1659 'Code accessed non-existent IV \'' . $iv . '\'',
1660 $self->_objClass . '->ivSplice',
1661 );
1662 }
1663  
1664 return undef;
1665 }
1666 }
1667  
1668 # Check that modifying the instance variable is allowed
1669 if (! $self->checkModify($iv)) {
1670  
1671 return @emptyList;
1672 }
1673  
1674 $refType = ref $self->{$iv};
1675 if ($refType eq 'ARRAY') {
1676  
1677 # This is a list. Set the parent file object's 'data modified' flag
1678 $self->doModify('ivSplice');
1679  
1680 if (scalar @list) {
1681 @returnArray = splice ( @{$self->{$iv}}, $offset, $length, @list );
1682 } elsif (defined $length) {
1683 @returnArray = splice ( @{$self->{$iv}}, $offset, $length );
1684 } else {
1685 @returnArray = splice ( @{$self->{$iv}}, $offset );
1686 }
1687  
1688 # Return the spliced value(s)
1689 return @returnArray;
1690  
1691 } else {
1692  
1693 # Not a list
1694 return @emptyList;
1695 }
1696 }
1697  
1698 sub ivIndex {
1699  
1700 # Returns an element at the specified index of an array instance variable
1701 #
1702 # Expected arguments
1703 # $iv - Which array instance variable to check
1704 # $index - Which element to return
1705 #
1706 # Return values
1707 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or the index is
1708 # outside the array, or improper arguments supplied)
1709 # Returns a scalar value on success
1710  
1711 my ($self, $iv, $index, $check) = @_;
1712  
1713 # Local variables
1714 my $refType;
1715  
1716 # Check for improper arguments
1717 if (! defined $iv || ! defined $index || defined $check) {
1718  
1719 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivIndex', @_);
1720 }
1721  
1722 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1723 # exist, get a default value from the default object stored in a global variable)
1724 if (! exists $self->{$iv}) {
1725  
1726 if ($self->isa('Games::Axmud::ModelObj::Room')) {
1727 $self = $axmud::DEFAULT_ROOM;
1728 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
1729 $self = $axmud::DEFAULT_EXIT;
1730 }
1731  
1732 if (! exists $self->{$iv}) {
1733  
1734 if ($axmud::CLIENT->debugCheckIVFlag) {
1735  
1736 $self->writeDebug(
1737 'Code accessed non-existent IV \'' . $iv . '\'',
1738 $self->_objClass . '->ivIndex'
1739 );
1740 }
1741  
1742 return undef;
1743 }
1744 }
1745  
1746 $refType = ref $self->{$iv};
1747 if ($refType eq 'ARRAY') {
1748  
1749 # This is a list. Perform the retrieval operation
1750 return ($self->{$iv}[$index]);
1751  
1752 } else {
1753  
1754 # Not a list
1755 return undef;
1756 }
1757 }
1758  
1759 sub ivFirst {
1760  
1761 # Returns an element at index 0 of an array instance variable
1762 # Note that ->ivFirst returns the value of the first element of an array, but ->ivLast
1763 # returns the index of the last element of an array
1764 #
1765 # Expected arguments
1766 # $iv - Which array instance variable to check
1767 #
1768 # Return values
1769 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or the array is empty,
1770 # or improper arguments supplied)
1771 # Returns a scalar value on success
1772  
1773 my ($self, $iv, $check) = @_;
1774  
1775 # Local variables
1776 my $refType;
1777  
1778 # Check for improper arguments
1779 if (! defined $iv || defined $check) {
1780  
1781 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivFirst', @_);
1782 }
1783  
1784 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1785 # exist, get a default value from the default object stored in a global variable)
1786 if (! exists $self->{$iv}) {
1787  
1788 if ($self->isa('Games::Axmud::ModelObj::Room')) {
1789 $self = $axmud::DEFAULT_ROOM;
1790 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
1791 $self = $axmud::DEFAULT_EXIT;
1792 }
1793  
1794 if (! exists $self->{$iv}) {
1795  
1796 if ($axmud::CLIENT->debugCheckIVFlag) {
1797  
1798 $self->writeDebug(
1799 'Code accessed non-existent IV \'' . $iv . '\'',
1800 $self->_objClass . '->ivFirst'
1801 );
1802 }
1803  
1804 return undef;
1805 }
1806 }
1807  
1808 $refType = ref $self->{$iv};
1809 if ($refType eq 'ARRAY') {
1810  
1811 # This is a list. Perform the retrieval operation
1812 return $self->{$iv}[0];
1813  
1814 } else {
1815  
1816 # Not a list
1817 return undef;
1818 }
1819 }
1820  
1821 sub ivLast {
1822  
1823 # Function to retrieve the the last index in an array instance variable
1824 # Note that ->ivFirst returns the value of the first element of an array, but ->ivLast
1825 # returns the index of the last element of an array
1826 #
1827 # Expected arguments
1828 # $iv - Which array instance variable to check
1829 #
1830 # Return values
1831 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1832 # supplied)
1833 # An integer upon success (which will be -1 if the array is empty)
1834  
1835 my ($self, $iv, $check) = @_;
1836  
1837 # Local variables
1838 my $refType;
1839  
1840 # Check for improper arguments
1841 if (! defined $iv || defined $check) {
1842  
1843 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivLast', @_);
1844 }
1845  
1846 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1847 # exist, get a default value from the default object stored in a global variable)
1848 if (! exists $self->{$iv}) {
1849  
1850 if ($self->isa('Games::Axmud::ModelObj::Room')) {
1851 $self = $axmud::DEFAULT_ROOM;
1852 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
1853 $self = $axmud::DEFAULT_EXIT;
1854 }
1855  
1856 if (! exists $self->{$iv}) {
1857  
1858 if ($axmud::CLIENT->debugCheckIVFlag) {
1859  
1860 $self->writeDebug(
1861 'Code accessed non-existent IV \'' . $iv . '\'',
1862 $self->_objClass . '->ivLast'
1863 );
1864 }
1865  
1866 return undef;
1867 }
1868 }
1869  
1870 $refType = ref $self->{$iv};
1871 if ($refType eq 'ARRAY') {
1872  
1873 # This is a list. Return the last index (-1 if the list is empty)
1874 return $#{$self->{$iv}};
1875  
1876 } else {
1877  
1878 # Not a list
1879 return undef;
1880 }
1881 }
1882  
1883 sub ivReplace {
1884  
1885 # Replaces an element at the specified index of an array instance variable
1886 #
1887 # Expected arguments
1888 # $iv - Which array instance variable to check
1889 # $index - Which element to replace
1890 #
1891 # Optional arguments
1892 # $scalar - The scalar to insert at the index (default is 'undef')
1893 #
1894 # Return values
1895 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
1896 # supplied)
1897 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
1898 # or if it begins with _, meaning modification not allowed using this function
1899 # 1 on success
1900  
1901 my ($self, $iv, $index, $scalar, $check) = @_;
1902  
1903 # Local variables
1904 my ($varRef, $refType);
1905  
1906 # Check for improper arguments
1907 if (! defined $iv || ! defined $index || defined $check) {
1908  
1909 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivReplace', @_);
1910 }
1911  
1912 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1913 # exist, initialise it using a default value from the default object stored in a global
1914 # variable)
1915 if (! exists $self->{$iv}) {
1916  
1917 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
1918  
1919 push (@$varRef, @{$axmud::DEFAULT_ROOM->{$iv}});
1920 $self->{$iv} = $varRef;
1921  
1922 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
1923  
1924 push (@$varRef, @{$axmud::DEFAULT_EXIT->{$iv}});
1925 $self->{$iv} = $varRef;
1926  
1927 } else {
1928  
1929 if ($axmud::CLIENT->debugCheckIVFlag) {
1930  
1931 $self->writeDebug(
1932 'Code accessed non-existent IV \'' . $iv . '\'',
1933 $self->_objClass . '->ivREplace',
1934 );
1935 }
1936  
1937 return undef;
1938 }
1939 }
1940  
1941 # Check that modifying the instance variable is allowed
1942 if (! $self->checkModify($iv)) {
1943  
1944 return undef;
1945 }
1946  
1947 $refType = ref $self->{$iv};
1948 if ($refType eq 'ARRAY') {
1949  
1950 # This is a list. Set the parent file object's 'data modified' flag
1951 $self->doModify('ivReplace');
1952  
1953 # Perform the replacement operation
1954 $self->{$iv}[$index] = $scalar;
1955  
1956 return 1;
1957  
1958 } else {
1959  
1960 # Not a list
1961 return undef;
1962 }
1963 }
1964  
1965 sub ivFind {
1966  
1967 # Checks all the elements of an array instance variable to see if one of them matches the
1968 # supplied scalar (exactly - $scalar and each element in the array are treated as strings)
1969 #
1970 # Expected arguments
1971 # $iv - Which array instance variable to check
1972 # $scalar - The scalar value to match
1973 #
1974 # Return values
1975 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or no matching
1976 # element found, or improper arguments supplied)
1977 # The index of the first element in the array that matches $scalar, on success
1978  
1979 my ($self, $iv, $scalar, $check) = @_;
1980  
1981 # Local variables
1982 my $refType;
1983  
1984 # Check for improper arguments
1985 if (! defined $iv || ! defined $scalar || defined $check) {
1986  
1987 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivFind', @_);
1988 }
1989  
1990 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
1991 # exist, get a default value from the default object stored in a global variable)
1992 if (! exists $self->{$iv}) {
1993  
1994 if ($self->isa('Games::Axmud::ModelObj::Room')) {
1995 $self = $axmud::DEFAULT_ROOM;
1996 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
1997 $self = $axmud::DEFAULT_EXIT;
1998 }
1999  
2000 if (! exists $self->{$iv}) {
2001  
2002 if ($axmud::CLIENT->debugCheckIVFlag) {
2003  
2004 $self->writeDebug(
2005 'Code accessed non-existent IV \'' . $iv . '\'',
2006 $self->_objClass . '->ivFind'
2007 );
2008 }
2009  
2010 return undef;
2011 }
2012 }
2013  
2014 $refType = ref $self->{$iv};
2015 if ($refType eq 'ARRAY') {
2016  
2017 # This is a list. Perform the search operation
2018 if (! @{$self->{$iv}}) {
2019  
2020 # List is empty
2021 return undef;
2022 }
2023  
2024 for (my $count = 0; $count < (scalar @{$self->{$iv}}); $count++) {
2025  
2026 if ($self->{$iv}[$count] eq $scalar) {
2027  
2028 return $count;
2029 }
2030 }
2031  
2032 # No matching element found
2033 return undef;
2034  
2035 } else {
2036  
2037 # Not a list
2038 return undef;
2039 }
2040 }
2041  
2042 sub ivMatch {
2043  
2044 # Performs a pattern match against all the elements of an array instance variable, looking
2045 # for the first one that returns 'true' in a Perl regex
2046 #
2047 # Expected arguments
2048 # $iv - Which array instance variable to check
2049 # $regEx - The regular expression to match (the portion between m/.../ )
2050 #
2051 # Optional arguments
2052 # $globalFlag - If 1, the match done is m/.../g
2053 # $ignoreCaseFlag - If 1, the match done is m/.../i
2054 #
2055 # Notes
2056 # If $globalFlag and $ignoreCaseFlag are both 1, the match done is m/.../gi
2057 #
2058 # Return values
2059 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or no matching
2060 # element found, or improper arguments supplied)
2061 # The index of the first element in the array that matches the regular expression, on
2062 # success
2063  
2064 my ($self, $iv, $regEx, $globalFlag, $ignoreCaseFlag, $check) = @_;
2065  
2066 # Local variables
2067 my $refType;
2068  
2069 # Check for improper arguments
2070 if (! defined $iv || ! defined $regEx || defined $check) {
2071  
2072 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivMatch', @_);
2073 }
2074  
2075 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2076 # exist, get a default value from the default object stored in a global variable)
2077 if (! exists $self->{$iv}) {
2078  
2079 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2080 $self = $axmud::DEFAULT_ROOM;
2081 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2082 $self = $axmud::DEFAULT_EXIT;
2083 }
2084  
2085 if (! exists $self->{$iv}) {
2086  
2087 if ($axmud::CLIENT->debugCheckIVFlag) {
2088  
2089 $self->writeDebug(
2090 'Code accessed non-existent IV \'' . $iv . '\'',
2091 $self->_objClass . '->ivMatch'
2092 );
2093 }
2094  
2095 return undef;
2096 }
2097 }
2098  
2099 $refType = ref $self->{$iv};
2100 if ($refType eq 'ARRAY') {
2101  
2102 # This is a list. Perform the match operation
2103 if (! @{$self->{$iv}}) {
2104  
2105 # List is empty
2106 return undef;
2107 }
2108  
2109 for (my $count = 0; $count < (scalar @{$self->{$iv}}); $count++) {
2110  
2111 if ($globalFlag && $ignoreCaseFlag) {
2112  
2113 if ($self->{$iv}[$count] =~ m/$regEx/gi) {
2114  
2115 # Match found
2116 return $count;
2117 }
2118  
2119 } elsif ($globalFlag) {
2120  
2121 if ($self->{$iv}[$count] =~ m/$regEx/g) {
2122  
2123 # Match found
2124 return $count;
2125 }
2126  
2127 } elsif ($ignoreCaseFlag) {
2128  
2129 if ($self->{$iv}[$count] =~ m/$regEx/i) {
2130  
2131 # Match found
2132 return $count;
2133 }
2134  
2135 } else {
2136  
2137 if ($self->{$iv}[$count] =~ m/$regEx/) {
2138  
2139 # Match found
2140 return $count;
2141 }
2142 }
2143 }
2144  
2145 # No matching element found
2146 return undef;
2147  
2148 } else {
2149  
2150 # Not a list
2151 return undef;
2152 }
2153 }
2154  
2155 sub ivEquals {
2156  
2157 # Checks all the elements of an array instance variable to see if one of them matches the
2158 # supplied scalar (treats $number and each element in the array as numbers)
2159 #
2160 # Expected arguments
2161 # $iv - Which array instance variable to check
2162 # $number - The scalar value to match
2163 #
2164 # Return values
2165 # 'undef' on failure (because $iv doesn't exist, or isn't an array, or improper arguments
2166 # supplied)
2167 # The index of the first element in the array that equals $number, on success
2168  
2169 my ($self, $iv, $number, $check) = @_;
2170  
2171 # Local variables
2172 my $refType;
2173  
2174 # Check for improper arguments
2175 if (! defined $iv || ! defined $number || defined $check) {
2176  
2177 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivEquals', @_);
2178 }
2179  
2180 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2181 # exist, get a default value from the default object stored in a global variable)
2182 if (! exists $self->{$iv}) {
2183  
2184 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2185 $self = $axmud::DEFAULT_ROOM;
2186 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2187 $self = $axmud::DEFAULT_EXIT;
2188 }
2189  
2190 if (! exists $self->{$iv}) {
2191  
2192 if ($axmud::CLIENT->debugCheckIVFlag) {
2193  
2194 $self->writeDebug(
2195 'Code accessed non-existent IV \'' . $iv . '\'',
2196 $self->_objClass . '->ivEquals'
2197 );
2198 }
2199  
2200 return undef;
2201 }
2202 }
2203  
2204 $refType = ref $self->{$iv};
2205 if ($refType eq 'ARRAY') {
2206  
2207 # This is a list. Perform the search operation
2208 if (! @{$self->{$iv}}) {
2209  
2210 # List is empty
2211 return undef;
2212 }
2213  
2214 for (my $count = 0; $count < (scalar @{$self->{$iv}}); $count++) {
2215  
2216 if (
2217 ! ($self->{$iv}[$count] =~ /\D/)
2218 && $self->{$iv}[$count] == $number
2219 ) {
2220 return $count;
2221 }
2222 }
2223  
2224 # No matching element found
2225 return undef;
2226  
2227 } else {
2228  
2229 # Not a list
2230 return undef;
2231 }
2232 }
2233  
2234 sub ivAdd {
2235  
2236 # Set key-value pair function for hash instance variables
2237 #
2238 # Expected arguments
2239 # $iv - Which hash instance variable to modify
2240 # $key - Which key to add
2241 # $value - What value to pair with the key
2242 #
2243 # Return values
2244 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2245 # supplied)
2246 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
2247 # or if it begins with _, meaning modification not allowed using this function
2248 # 1 on success
2249  
2250 my ($self, $iv, $key, $value, $check) = @_;
2251  
2252 # Local variables
2253 my ($varRef, $refType);
2254  
2255 # Check for improper arguments
2256 if (! defined $iv || ! defined $key || defined $check) {
2257  
2258 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivAdd', @_);
2259 }
2260  
2261 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2262 # exist, initialise it using a default value from the default object stored in a global
2263 # variable)
2264 if (! exists $self->{$iv}) {
2265  
2266 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
2267  
2268 %$varRef = %{$axmud::DEFAULT_ROOM->{$iv}};
2269 $self->{$iv} = $varRef;
2270  
2271 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
2272  
2273 %$varRef = %{$axmud::DEFAULT_EXIT->{$iv}};
2274 $self->{$iv} = $varRef;
2275  
2276 } else {
2277  
2278 if ($axmud::CLIENT->debugCheckIVFlag) {
2279  
2280 $self->writeDebug(
2281 'Code accessed non-existent IV \'' . $iv . '\'',
2282 $self->_objClass . '->ivAdd',
2283 );
2284 }
2285  
2286 return undef;
2287 }
2288 }
2289  
2290 # Check that modifying the instance variable is allowed
2291 if (! $self->checkModify($iv)) {
2292  
2293 return undef;
2294 }
2295  
2296 $refType = ref $self->{$iv};
2297 if ($refType eq 'HASH') {
2298  
2299 # This is a hash. Set the parent file object's 'data modified' flag
2300 $self->doModify('ivAdd');
2301  
2302 # Add the key-value pair
2303 $self->{$iv}{$key} = $value;
2304 return 1;
2305  
2306 } else {
2307  
2308 # Not a hash
2309 return undef;
2310 }
2311 }
2312  
2313 sub ivIncHash {
2314  
2315 # Increments the value of a key in a hash instance variable
2316 #
2317 # Expected arguments
2318 # $iv - Which hash instance variable to modify
2319 # $key - Which key to increment
2320 #
2321 # Return values
2322 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2323 # supplied)
2324 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
2325 # or if it begins with _, meaning modification not allowed using this function
2326 # 'undef' if the value matching $key isn't a number or if the specified $key doesn't exist
2327 # in the hash
2328 # 1 on success
2329  
2330 my ($self, $iv, $key, $check) = @_;
2331  
2332 # Local variables
2333 my ($varRef, $refType, $value);
2334  
2335 # Check for improper arguments
2336 if (! defined $iv || ! defined $key || defined $check) {
2337  
2338 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivIncHash', @_);
2339 }
2340  
2341 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2342 # exist, initialise it using a default value from the default object stored in a global
2343 # variable)
2344 if (! exists $self->{$iv}) {
2345  
2346 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
2347  
2348 %$varRef = %{$axmud::DEFAULT_ROOM->{$iv}};
2349 $self->{$iv} = $varRef;
2350  
2351 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
2352  
2353 %$varRef = %{$axmud::DEFAULT_EXIT->{$iv}};
2354 $self->{$iv} = $varRef;
2355  
2356 } else {
2357  
2358 if ($axmud::CLIENT->debugCheckIVFlag) {
2359  
2360 $self->writeDebug(
2361 'Code accessed non-existent IV \'' . $iv . '\'',
2362 $self->_objClass . '->ivAdd',
2363 );
2364 }
2365  
2366 return undef;
2367 }
2368 }
2369  
2370 # Check that modifying the instance variable is allowed
2371 if (! $self->checkModify($iv)) {
2372  
2373 return undef;
2374 }
2375  
2376 $refType = ref $self->{$iv};
2377 if ($refType eq 'HASH') {
2378  
2379 # Check the specified key exists
2380 if (! exists $self->{$iv}{$key}) {
2381  
2382 return undef;
2383  
2384 # Check that the value is a number
2385 } elsif ($self->{$iv}{$key} =~ m/\D/) {
2386  
2387 return undef;
2388 }
2389  
2390 # This is a hash. Set the parent file object's 'data modified' flag
2391 $self->doModify('ivIncHash');
2392  
2393 # Increment the value
2394 ($self->{$iv}{$key})++;
2395 return 1;
2396  
2397 } else {
2398  
2399 # Not a hash
2400 return undef;
2401 }
2402 }
2403  
2404 sub ivDecHash {
2405  
2406 # Decrements the value of a key in a hash instance variable
2407 #
2408 # Expected arguments
2409 # $iv - Which hash instance variable to modify
2410 # $key - Which key to decrement
2411 #
2412 # Return values
2413 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2414 # supplied)
2415 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
2416 # or if it begins with _, meaning modification not allowed using this function
2417 # 'undef' if the value matching $key isn't a number or if the specified $key doesn't exist
2418 # in the hash
2419 # 1 on success
2420  
2421 my ($self, $iv, $key, $check) = @_;
2422  
2423 # Local variables
2424 my ($varRef, $refType, $value);
2425  
2426 # Check for improper arguments
2427 if (! defined $iv || ! defined $key || defined $check) {
2428  
2429 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivDecHash', @_);
2430 }
2431  
2432 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2433 # exist, initialise it using a default value from the default object stored in a global
2434 # variable)
2435 if (! exists $self->{$iv}) {
2436  
2437 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
2438  
2439 %$varRef = %{$axmud::DEFAULT_ROOM->{$iv}};
2440 $self->{$iv} = $varRef;
2441  
2442 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
2443  
2444 %$varRef = %{$axmud::DEFAULT_EXIT->{$iv}};
2445 $self->{$iv} = $varRef;
2446  
2447 } else {
2448  
2449 if ($axmud::CLIENT->debugCheckIVFlag) {
2450  
2451 $self->writeDebug(
2452 'Code accessed non-existent IV \'' . $iv . '\'',
2453 $self->_objClass . '->ivAdd',
2454 );
2455 }
2456  
2457 return undef;
2458 }
2459 }
2460  
2461 # Check that modifying the instance variable is allowed
2462 if (! $self->checkModify($iv)) {
2463  
2464 return undef;
2465 }
2466  
2467 $refType = ref $self->{$iv};
2468 if ($refType eq 'HASH') {
2469  
2470 # Check the specified key exists
2471 if (! exists $self->{$iv}{$key}) {
2472  
2473 return undef;
2474  
2475 # Check that the value is a number
2476 } elsif ($self->{$iv}{$key} =~ m/\D/) {
2477  
2478 return undef;
2479 }
2480  
2481 # This is a hash. Set the parent file object's 'data modified' flag
2482 $self->doModify('ivDecHash');
2483  
2484 # Decrement the value
2485 ($self->{$iv}{$key})--;
2486 return 1;
2487  
2488 } else {
2489  
2490 # Not a hash
2491 return undef;
2492 }
2493 }
2494  
2495 sub ivShow {
2496  
2497 # Function to retrieve the value of a key-value pair in hash instance variables
2498 #
2499 # Expected arguments
2500 # $iv - Which hash instance variable to test
2501 # $key - Which key-value pair to retrieve
2502 #
2503 # Return values
2504 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2505 # supplied)
2506 # The key's value on success
2507  
2508 my ($self, $iv, $key, $check) = @_;
2509  
2510 # Local variables
2511 my $refType;
2512  
2513 # Check for improper arguments
2514 if (! defined $iv || ! defined $key || defined $check) {
2515  
2516 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivShow', @_);
2517 }
2518  
2519 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2520 # exist, get a default value from the default object stored in a global variable)
2521 if (! exists $self->{$iv}) {
2522  
2523 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2524 $self = $axmud::DEFAULT_ROOM;
2525 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2526 $self = $axmud::DEFAULT_EXIT;
2527 }
2528  
2529 if (! exists $self->{$iv}) {
2530  
2531 if ($axmud::CLIENT->debugCheckIVFlag) {
2532  
2533 $self->writeDebug(
2534 'Code accessed non-existent IV \'' . $iv . '\'',
2535 $self->_objClass . '->ivShow'
2536 );
2537 }
2538  
2539 return undef;
2540 }
2541 }
2542  
2543 $refType = ref $self->{$iv};
2544 if ($refType eq 'HASH') {
2545  
2546 # This is a hash. Show the value from the key-value pair
2547 return $self->{$iv}{$key};
2548  
2549 } else {
2550  
2551 # Not a hash
2552 return undef;
2553 }
2554 }
2555  
2556 sub ivDelete {
2557  
2558 # Function to delete a key-value pair in hash instance variables
2559 #
2560 # Expected arguments
2561 # $iv - Which hash instance variable to modify
2562 # $key - Which key-value pair to delete
2563 #
2564 # Return values
2565 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2566 # supplied)
2567 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
2568 # or if it begins with _, meaning modification not allowed using this function
2569 # 1 on success
2570  
2571 my ($self, $iv, $key, $check) = @_;
2572  
2573 # Local variables
2574 my ($varRef, $refType);
2575  
2576 # Check for improper arguments
2577 if (! defined $iv || ! defined $key || defined $check) {
2578  
2579 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivDelete', @_);
2580 }
2581  
2582 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2583 # exist, initialise it using a default value from the default object stored in a global
2584 # variable)
2585 if (! exists $self->{$iv}) {
2586  
2587 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
2588  
2589 %$varRef = %{$axmud::DEFAULT_ROOM->{$iv}};
2590 $self->{$iv} = $varRef;
2591  
2592 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
2593  
2594 %$varRef = %{$axmud::DEFAULT_EXIT->{$iv}};
2595 $self->{$iv} = $varRef;
2596  
2597 } else {
2598  
2599 if ($axmud::CLIENT->debugCheckIVFlag) {
2600  
2601 $self->writeDebug(
2602 'Code accessed non-existent IV \'' . $iv . '\'',
2603 $self->_objClass . '->ivAdd',
2604 );
2605 }
2606  
2607 return undef;
2608 }
2609 }
2610  
2611 # Check that modifying the instance variable is allowed
2612 if (! $self->checkModify($iv)) {
2613  
2614 return undef;
2615 }
2616  
2617 $refType = ref $self->{$iv};
2618 if ($refType eq 'HASH') {
2619  
2620 # This is a hash. Check the key-value pair exists
2621 if (! exists $self->{$iv}{$key}) {
2622  
2623 return undef;
2624 }
2625  
2626 # Set the parent file object's 'data modified' flag
2627 $self->doModify('ivDelete');
2628  
2629 # Delete the key-value pair
2630 delete $self->{$iv}{$key};
2631 return 1;
2632  
2633 } else {
2634  
2635 # Not a hash
2636 return undef;
2637 }
2638 }
2639  
2640 sub ivExists {
2641  
2642 # Exists function for hash instance variables
2643 #
2644 # Expected arguments
2645 # $iv - Which hash instance variable to test
2646 # $key - Which key-value pair to test
2647 #
2648 # Return values
2649 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2650 # supplied)
2651 # 1 on success
2652  
2653 my ($self, $iv, $key, $check) = @_;
2654  
2655 # Local variables
2656 my $refType;
2657  
2658 # Check for improper arguments
2659 if (! defined $iv || ! defined $key || defined $check) {
2660  
2661 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivExists', @_);
2662 }
2663  
2664 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2665 # exist, get a default value from the default object stored in a global variable)
2666 if (! exists $self->{$iv}) {
2667  
2668 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2669 $self = $axmud::DEFAULT_ROOM;
2670 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2671 $self = $axmud::DEFAULT_EXIT;
2672 }
2673  
2674 if (! exists $self->{$iv}) {
2675  
2676 if ($axmud::CLIENT->debugCheckIVFlag) {
2677  
2678 $self->writeDebug(
2679 'Code accessed non-existent IV \'' . $iv . '\'',
2680 $self->_objClass . '->ivExists'
2681 );
2682 }
2683  
2684 return undef;
2685 }
2686 }
2687  
2688 $refType = ref $self->{$iv};
2689 if ($refType eq 'HASH') {
2690  
2691 # This is a hash. Check the key-value pair exists
2692 if (exists $self->{$iv}{$key}) {
2693 return 1;
2694 } else {
2695 return undef;
2696 }
2697  
2698 } else {
2699  
2700 # Not a hash
2701 return undef;
2702 }
2703 }
2704  
2705 sub ivKeys {
2706  
2707 # Function to retrieve list of keys from hash instance variables
2708 #
2709 # Expected arguments
2710 # $iv - Which hash instance variable to test
2711 #
2712 # Return values
2713 # An empty list on failure (because $iv doesn't exist, or isn't a hash, or improper
2714 # arguments supplied)
2715 # The list of keys on success (which might be empty)
2716  
2717 my ($self, $iv, $check) = @_;
2718  
2719 # Local variables
2720 my (
2721 $refType,
2722 @emptyList,
2723 );
2724  
2725 # Check for improper arguments
2726 if (! defined $iv || defined $check) {
2727  
2728 $axmud::CLIENT->writeImproper($self->_objClass . '->ivSet', @_);
2729 return @emptyList;
2730 }
2731  
2732 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2733 # exist, get a default value from the default object stored in a global variable)
2734 if (! exists $self->{$iv}) {
2735  
2736 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2737 $self = $axmud::DEFAULT_ROOM;
2738 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2739 $self = $axmud::DEFAULT_EXIT;
2740 }
2741  
2742 if (! exists $self->{$iv}) {
2743  
2744 if ($axmud::CLIENT->debugCheckIVFlag) {
2745  
2746 $self->writeDebug(
2747 'Code accessed non-existent IV \'' . $iv . '\'',
2748 $self->_objClass . '->ivKeys'
2749 );
2750 }
2751  
2752 return undef;
2753 }
2754 }
2755  
2756 $refType = ref $self->{$iv};
2757 if ($refType eq 'HASH') {
2758  
2759 # This is a hash. Return a list of keys
2760 return (keys %{$self->{$iv}} );
2761  
2762 } else {
2763  
2764 # Not a hash
2765 return @emptyList;
2766 }
2767 }
2768  
2769 sub ivValues {
2770  
2771 # Function to retrieve list of values from hash instance variables
2772 #
2773 # Expected arguments
2774 # $iv - Which hash instance variable to test
2775 #
2776 # Return values
2777 # An empty list on failure (because $iv doesn't exist, or isn't a hash, or improper
2778 # arguments supplied)
2779 # The list of values on success
2780  
2781 my ($self, $iv, $check) = @_;
2782  
2783 # Local variables
2784 my (
2785 $refType,
2786 @emptyList,
2787 );
2788  
2789 # Check for improper arguments
2790 if (! defined $iv || defined $check) {
2791  
2792 $axmud::CLIENT->writeImproper($self->_objClass . '->ivValues', @_);
2793 return @emptyList;
2794 }
2795  
2796 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2797 # exist, get a default value from the default object stored in a global variable)
2798 if (! exists $self->{$iv}) {
2799  
2800 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2801 $self = $axmud::DEFAULT_ROOM;
2802 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2803 $self = $axmud::DEFAULT_EXIT;
2804 }
2805  
2806 if (! exists $self->{$iv}) {
2807  
2808 if ($axmud::CLIENT->debugCheckIVFlag) {
2809  
2810 $self->writeDebug(
2811 'Code accessed non-existent IV \'' . $iv . '\'',
2812 $self->_objClass . '->ivValues'
2813 );
2814 }
2815  
2816 return undef;
2817 }
2818 }
2819  
2820 $refType = ref $self->{$iv};
2821 if ($refType eq 'HASH') {
2822  
2823 # This is a hash. Return a list of values
2824 return ( values %{$self->{$iv}} );
2825  
2826 } else {
2827  
2828 # Not a hash
2829 return @emptyList;
2830 }
2831 }
2832  
2833 sub ivPairs {
2834  
2835 # Function to retrieve the number of key-value pairs in a hash instance variables
2836 #
2837 # Expected arguments
2838 # $iv - Which hash instance variable to test
2839 #
2840 # Return values
2841 # 'undef' on failure (because $iv doesn't exist, or isn't a hash, or improper arguments
2842 # supplied)
2843 # The number of key-value pairs on success (may be 0)
2844  
2845 my ($self, $iv, $check) = @_;
2846  
2847 # Local variables
2848 my $refType;
2849  
2850 # Check for improper arguments
2851 if (! defined $iv || defined $check) {
2852  
2853 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivPairs', @_);
2854 }
2855  
2856 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2857 # exist, get a default value from the default object stored in a global variable)
2858 if (! exists $self->{$iv}) {
2859  
2860 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2861 $self = $axmud::DEFAULT_ROOM;
2862 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2863 $self = $axmud::DEFAULT_EXIT;
2864 }
2865  
2866 if (! exists $self->{$iv}) {
2867  
2868 if ($axmud::CLIENT->debugCheckIVFlag) {
2869  
2870 $self->writeDebug(
2871 'Code accessed non-existent IV \'' . $iv . '\'',
2872 $self->_objClass . '->ivPairs'
2873 );
2874 }
2875  
2876 return undef;
2877 }
2878 }
2879  
2880 $refType = ref $self->{$iv};
2881 if ($refType eq 'HASH') {
2882  
2883 # This is a hash. Return the number of key-value pairs
2884 return scalar (keys %{$self->{$iv}} );
2885  
2886 } else {
2887  
2888 # Not a hash
2889 return undef;
2890 }
2891 }
2892  
2893 sub ivList {
2894  
2895 # Function to list all the instance variables in this object package
2896 #
2897 # Expected arguments
2898 # (none besides $self)
2899 #
2900 # Return values
2901 # An empty list on improper arguments
2902 # A list of instance variable names on success
2903  
2904 my ($self, $check) = @_;
2905  
2906 # Local variables
2907 my @emptyList;
2908  
2909 # Check for improper arguments
2910 if (defined $check) {
2911  
2912 $axmud::CLIENT->writeImproper($self->_objClass . '->ivList', @_);
2913 return @emptyList;
2914 }
2915  
2916 # (For room and exit objects, the full list of IVs is only obtainable from the default
2917 # object stored in a global variable)
2918 if ($self->isa('Games::Axmud::ModelObj::Room')) {
2919 $self = $axmud::DEFAULT_ROOM;
2920 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
2921 $self = $axmud::DEFAULT_EXIT;
2922 }
2923  
2924 return keys (%{$self});
2925 }
2926  
2927 sub ivEmpty {
2928  
2929 # Function to empty an instance variable. If it's a scalar, it's set to 'undef'. If it's a
2930 # list or a hash, the list or hash is emptied
2931 #
2932 # Expected arguments
2933 # $iv - Which instance variable to modify
2934 #
2935 # Return values
2936 # 'undef' on failure (because $iv doesn't exist, or isn't a scalar / list / hash, or
2937 # improper arguments supplied)
2938 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
2939 # or if it begins with _, meaning modification not allowed using this function
2940 # 1 on success
2941  
2942 my ($self, $iv, $check) = @_;
2943  
2944 # Local variables
2945 my ($varRef, $refType);
2946  
2947 # Check for improper arguments
2948 if (! defined $iv || defined $check) {
2949  
2950 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivEmpty', @_);
2951 }
2952  
2953 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2954 # exist, get a default value from the default object stored in a global variable)
2955 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
2956 # exist, initialise it using a default value from the default object stored in a global
2957 # variable)
2958 if (! exists $self->{$iv}) {
2959  
2960 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
2961 $varRef = $axmud::DEFAULT_ROOM->{$iv};
2962 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
2963 $varRef = $axmud::DEFAULT_EXIT->{$iv};
2964 } else {
2965  
2966 if ($axmud::CLIENT->debugCheckIVFlag) {
2967  
2968 $self->writeDebug(
2969 'Code accessed non-existent IV \'' . $iv . '\'',
2970 $self->_objClass . '->ivEmpty',
2971 );
2972 }
2973  
2974 return undef;
2975 }
2976  
2977 } else {
2978  
2979 $varRef = $self->{$iv};
2980 }
2981  
2982 # Check that modifying the instance variable is allowed
2983 if (! $self->checkModify($iv)) {
2984  
2985 return undef;
2986 }
2987  
2988 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
2989 # a scalar instance variable; so treat it as a scalar
2990 $refType = ref $varRef;
2991 if ($refType eq '' || $refType eq 'ARRAY' || $refType eq 'HASH') {
2992  
2993 # This is a scalar, array or hash. Set the parent file object's 'data modified' flag
2994 $self->doModify('ivEmpty');
2995  
2996 if ($refType eq '') {
2997  
2998 # A scalar. Set it to 'undef'
2999 $self->{$iv} = undef;
3000 return 1;
3001  
3002 } elsif ($refType eq 'ARRAY') {
3003  
3004 # A list. Empty the list
3005 $self->{$iv} = [];
3006 return 1;
3007  
3008 } elsif ($refType eq 'HASH') {
3009  
3010 # A hash. Empty the hash
3011 $self->{$iv} = {};
3012 return 1;
3013 }
3014  
3015 } else {
3016  
3017 # Something else. Return 'undef'
3018 return undef;
3019 }
3020 }
3021  
3022 sub ivType {
3023  
3024 # Returns the type of the instance variable - 'scalar', 'list', 'hash'
3025 # According to Axmud conventions, instance variables should be one of these three. If you
3026 # use some other reference (to a block of code, for example), ->ivType will just return
3027 # 'undef'
3028 #
3029 # Expected arguments
3030 # $iv - Which instance variable to check
3031 #
3032 # Return values
3033 # 'undef' on failure (because $iv doesn't exist, or improper arguments supplied)
3034 # One of the values 'scalar', 'list' or 'hash' on success
3035  
3036 my ($self, $iv, $check) = @_;
3037  
3038 # Local variables
3039 my $refType;
3040  
3041 # Check for improper arguments
3042 if (! defined $iv || defined $check) {
3043  
3044 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivType', @_);
3045 }
3046  
3047 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
3048 # exist, get a default value from the default object stored in a global variable)
3049 if (! exists $self->{$iv}) {
3050  
3051 if ($self->isa('Games::Axmud::ModelObj::Room')) {
3052 $self = $axmud::DEFAULT_ROOM;
3053 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
3054 $self = $axmud::DEFAULT_EXIT;
3055 }
3056  
3057 if (! exists $self->{$iv}) {
3058  
3059 if ($axmud::CLIENT->debugCheckIVFlag) {
3060  
3061 $self->writeDebug(
3062 'Code accessed non-existent IV \'' . $iv . '\'',
3063 $self->_objClass . '->ivType'
3064 );
3065 }
3066  
3067 return undef;
3068 }
3069 }
3070  
3071 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
3072 # a scalar instance variable; so treat it as a scalar
3073 $refType = ref $self->{$iv};
3074 if ($refType eq 'ARRAY') {
3075  
3076 return 'list';
3077  
3078 } elsif ($refType eq 'HASH') {
3079  
3080 return 'hash';
3081  
3082 } else {
3083  
3084 # Assume it's a scalar
3085 return 'scalar';
3086 }
3087 }
3088  
3089 sub ivPeek {
3090  
3091 # Returns the contents of a scalar, array or hash instance variable as a list
3092 #
3093 # Expected arguments
3094 # $iv - Which instance variable to check
3095 #
3096 # Return values
3097 # An empty list on failure (because $iv doesn't exist, isn't a scalar / list / hash or
3098 # improper arguments supplied)
3099 # Otherwise returns @returnArray, the list of contents (may be an empty list)
3100  
3101 my ($self, $iv, $check) = @_;
3102  
3103 # Local variables
3104 my (
3105 $refType,
3106 @emptyList, @returnArray,
3107 );
3108  
3109 # Check for improper arguments
3110 if (! defined $iv || defined $check) {
3111  
3112 $axmud::CLIENT->writeImproper($self->_objClass . '->ivSet', @_);
3113 return @emptyList;
3114 }
3115  
3116 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
3117 # exist, get a default value from the default object stored in a global variable)
3118 if (! exists $self->{$iv}) {
3119  
3120 if ($self->isa('Games::Axmud::ModelObj::Room')) {
3121 $self = $axmud::DEFAULT_ROOM;
3122 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
3123 $self = $axmud::DEFAULT_EXIT;
3124 }
3125  
3126 if (! exists $self->{$iv}) {
3127  
3128 if ($axmud::CLIENT->debugCheckIVFlag) {
3129  
3130 $self->writeDebug(
3131 'Code accessed non-existent IV \'' . $iv . '\'',
3132 $self->_objClass . '->ivPeek'
3133 );
3134 }
3135  
3136 return undef;
3137 }
3138 }
3139  
3140 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
3141 # a scalar instance variable; so treat it as a scalar
3142 $refType = ref $self->{$iv};
3143 if ($refType eq '') {
3144  
3145 # It's a scalar (presumably). Return the scalar as a 1-element list. Need to check that
3146 # the value stored in the IV is defined, otherwise we get an error
3147 if (defined ${$self->{$iv}}) {
3148  
3149 @returnArray = ( ${$self->{$iv}} );
3150 }
3151  
3152 return @returnArray;
3153  
3154 } elsif ($refType eq 'ARRAY') {
3155  
3156 # It's a list. Simply return the list
3157 return @{$self->{$iv}};
3158  
3159 } elsif ($refType eq 'HASH') {
3160  
3161 # It's a hash. Unwind the array into a flat list and return the list
3162 @returnArray = %{$self->{$iv}};
3163 return @returnArray;
3164  
3165 } else {
3166  
3167 # Something else
3168 return @emptyList;
3169 }
3170 }
3171  
3172 sub ivPoke {
3173  
3174 # Sets the contents of a scalar, array or hash instance variable
3175 #
3176 # Expected arguments
3177 # $iv - Which instance variable to check
3178 # @list - List of values to set
3179 #
3180 # Notes
3181 # If this IV is a scalar, the IV is set to the first value in @list (if @list is empty,
3182 # the IV is set to 'undef')
3183 # If this IV is a list, the IV is set to the whole of @list (if @list is empty, the IV is
3184 # set to an empty list)
3185 # If this IV is a hash, the IV is set to the whole of @list, so @list is expected to be a
3186 # (key, value, key, value...) sequence. If the last value is missing, the value in
3187 # that key-value pair is set to 'undef'. If @list is empty, the hash is emptied.
3188 #
3189 # Return values
3190 # 'undef' on failure (because $iv doesn't exist or improper arguments supplied)
3191 # 'undef' if $iv is a system constant (specified by the keys in GA::Client->constIVHash)
3192 # or if it begins with _, meaning modification not allowed using this function
3193 # 1 on success
3194  
3195 my ($self, $iv, @list) = @_;
3196  
3197 # Local variables
3198 my (
3199 $varRef, $refType, $debugFlag,
3200 %hash,
3201 );
3202  
3203 # Check for improper arguments
3204 if (! defined $iv) {
3205  
3206 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivPoke', @_);
3207 }
3208  
3209 # Check the instance variable exists at all (but for room and exit objects, if it doesn't
3210 # exist, initialise it using a default value from the default object stored in a global
3211 # variable)
3212 if (! exists $self->{$iv}) {
3213  
3214 if ($self->isa('Games::Axmud::ModelObj::Room') && exists $axmud::DEFAULT_ROOM->{$iv}) {
3215 $varRef = $axmud::DEFAULT_ROOM->{$iv};
3216 } elsif ($self->isa('Games::Axmud::Obj::Exit') && exists $axmud::DEFAULT_EXIT->{$iv}) {
3217 $varRef = $axmud::DEFAULT_EXIT->{$iv};
3218 } else {
3219  
3220 if ($axmud::CLIENT->debugCheckIVFlag) {
3221  
3222 $self->writeDebug(
3223 'Code accessed non-existent IV \'' . $iv . '\'',
3224 $self->_objClass . '->ivPoke',
3225 );
3226 }
3227  
3228 return undef;
3229 }
3230  
3231 } else {
3232  
3233 $varRef = $self->{$iv};
3234 }
3235  
3236 # Check that modifying the instance variable is allowed
3237 if (! $self->checkModify($iv)) {
3238  
3239 return undef;
3240 }
3241  
3242 # Set the parent file's 'data modified' flag
3243 $self->doModify('ivPoke');
3244  
3245 # According to Axmud's coding conventions, if ref() doesn't return 'ARRAY' or 'HASH', it's
3246 # saved in one of the scalar IVs (might be a scalar value or a blessed reference)
3247 $refType = ref $varRef;
3248 if ($refType eq 'ARRAY') {
3249  
3250 # It's a list. Set the list
3251 $self->{$iv} = \@list;
3252  
3253 return 1;
3254  
3255 } elsif ($refType eq 'HASH') {
3256  
3257 # It's a hash. Convert @list into a hash, and set the hash
3258 %hash = @list;
3259 $self->{$iv} = \%hash;
3260  
3261 return 1;
3262  
3263 } else {
3264  
3265 if (! @list) {
3266 $self->{$iv} = undef;
3267 } else {
3268 $self->{$iv} = $list[0];
3269 }
3270  
3271 return 1;
3272 }
3273 }
3274  
3275 sub ivMember {
3276  
3277 # See if the instance variable exists, or not
3278 #
3279 # Expected arguments
3280 # $iv - Which instance variable to check
3281 #
3282 # Return values
3283 # 'undef' on improper arguments or if the instance variable doesn't exist
3284 # 1 if the instance variable exists
3285  
3286 my ($self, $iv, $check) = @_;
3287  
3288 # Check for improper arguments
3289 if (! defined $iv || defined $check) {
3290  
3291 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivMember', @_);
3292 }
3293  
3294 # (For room and exit objects, the full list of IVs is only obtainable from the default
3295 # object stored in a global variable)
3296 if ($self->isa('Games::Axmud::ModelObj::Room')) {
3297 $self = $axmud::DEFAULT_ROOM;
3298 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
3299 $self = $axmud::DEFAULT_EXIT;
3300 }
3301  
3302 # Check the instance variable exists at all
3303 if (! exists $self->{$iv}) {
3304  
3305 return undef;
3306  
3307 } else {
3308  
3309 return 1;
3310 }
3311 }
3312  
3313 sub ivCreate {
3314  
3315 # Creates a new IV of a specified type. If it's a scalar, its initial value is 'undef'.
3316 # If it's a list or hash, its initial value is an empty list of hash
3317 # The reason to call this function - rather than to use a statement like
3318 # $self->{...} = ...
3319 # ...is, of course, to make sure that parent file object's ->modifyFlag (if any) is set
3320 # This function is provided for profile templates (and probably isn't useful for anything
3321 # else)
3322 #
3323 # Expected arguments
3324 # $iv - The name of the new instance variable
3325 # $type - 'scalar', 'list' (or 'array'), or 'hash'
3326 #
3327 # Return values
3328 # 'undef' on failure (because $iv already exists or improper arguments supplied)
3329 # 1 on success
3330  
3331 my ($self, $iv, $type, $check) = @_;
3332  
3333 # Local variables
3334 my $defaultObj;
3335  
3336 # Check for improper arguments
3337 if (
3338 ! defined $iv || ! defined $type
3339 || ($type ne 'scalar' && $type ne 'list' && $type ne 'array' && $type ne 'hash')
3340 || defined $check
3341 ) {
3342 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivCreate', @_);
3343 }
3344  
3345 # (For room and exit objects, the full list of IVs is only obtainable from the default
3346 # object stored in a global variable)
3347 if ($self->isa('Games::Axmud::ModelObj::Room')) {
3348 $defaultObj = $axmud::DEFAULT_ROOM;
3349 } elsif ($self->isa('Games::Axmud::Obj::Exit')) {
3350 $defaultObj = $axmud::DEFAULT_EXIT;
3351 } else {
3352 $defaultObj = $self;
3353 }
3354  
3355 # Check the variable doesn't already exist
3356 if (exists $defaultObj->{$iv}) {
3357  
3358 return undef;
3359 }
3360  
3361 # Create the variable
3362 if ($type eq 'list' || $type eq 'array') {
3363 $self->{$iv} = [];
3364 } elsif ($type eq 'hash') {
3365 $self->{$iv} = {};
3366 } else {
3367 $self->{$iv} = undef;
3368 }
3369  
3370 # Set the parent file object's 'data modified' flag
3371 $self->doModify('ivCreate');
3372  
3373 return 1;
3374 }
3375  
3376 sub ivDestroy {
3377  
3378 # Destroys an existing IV
3379 # The reason to call this function - rather than to use a statement like
3380 # delete $self->{...}
3381 # ...is, of course, to make sure that parent file object's ->modifyFlag (if any) is set
3382 # This function is provided for profile templates (and probably isn't useful for anything
3383 # else)
3384 # IVs which being with an underline can't be destroyed (we definitely don't want to
3385 # destory one of the four standard IVs, used by all Perl objects, by mistake)
3386 #
3387 # Expected arguments
3388 # $iv - The name of the doomed instance variable
3389 #
3390 # Return values
3391 # 'undef' on failure (because $iv doesn't exist, the property begins with an underline
3392 # or improper arguments supplied)
3393 # 1 on success
3394  
3395 my ($self, $iv, $check) = @_;
3396  
3397 # Check for improper arguments
3398 if (! defined $iv || defined $check) {
3399  
3400 return $axmud::CLIENT->writeImproper($self->_objClass . '->ivCreate', @_);
3401 }
3402  
3403 # Check the variable exists
3404 if (! exists $self->{$iv}) {
3405  
3406 return undef;
3407  
3408 # Check it doesn't begin with an underline
3409 } elsif (substr($iv, 0, 1) eq '_') {
3410  
3411 return undef;
3412 }
3413  
3414 # Destroy the variable
3415 delete $self->{$iv};
3416  
3417 # Set the parent file object's 'data modified' flag
3418 $self->doModify('ivDestroy');
3419  
3420 return 1;
3421 }
3422  
3423 # Text-writing methods
3424  
3425 sub writeText {
3426  
3427 # Can be called by anything
3428 # Passes a set of arguments to GA::Obj::TextView->showSystemText. If it's not possible to
3429 # display a message in a 'main' window, writes to the terminal (and the Client Console
3430 # window, the next time it's opened)
3431 #
3432 # Expected arguments
3433 # (none besides $self)
3434 #
3435 # Optional arguments
3436 # @args - A list of arguments to pass on. The first one is the system message itself
3437 #
3438 # Return values
3439 # Returns the return value of the call to GA::Obj::TextView->showSystemText, or 'undef' if
3440 # forced to write to the terminal
3441  
3442 my ($self, @args) = @_;
3443  
3444 # Local variables
3445 my $msg;
3446  
3447 # (No improper arguments to check)
3448  
3449 # If this object has a ->session IV, then we can find its default tab
3450 if (exists $self->{'session'} && $self->session && $self->session->defaultTabObj) {
3451  
3452 return $self->session->defaultTabObj->textViewObj->showSystemText(@args);
3453  
3454 # Otherwise, try the GA::Client's current session (the visible session in the last 'main'
3455 # window to receive focus)
3456 } elsif ($axmud::CLIENT->currentSession && $axmud::CLIENT->currentSession->defaultTabObj) {
3457  
3458 return
3459 $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showSystemText(@args);
3460  
3461 } else {
3462  
3463 # Otherwise, we're forced to write to the terminal. The message is also stored in
3464 # GA::Client->systemMsgList, so it can be viewed in the Client Console window, if and
3465 # when the user opens it
3466 $msg = $args[0];
3467 if (! defined $msg) {
3468  
3469 $msg = '<<undef>>';
3470 }
3471  
3472 $msg = 'SYSTEM: ' . $msg;
3473  
3474 $axmud::CLIENT->add_systemMsg('system', $msg);
3475 print $msg . "\n";
3476  
3477 return undef;
3478 }
3479 }
3480  
3481 sub writeError {
3482  
3483 # Can be called by anything
3484 # Passes a set of arguments to GA::Obj::TextView->showError. If it's not possible to display
3485 # a message in a 'main' window, writes to the terminal (and the Client Console window, the
3486 # next time it's opened)
3487 #
3488 # Expected arguments
3489 # (none besides $self)
3490 #
3491 # Optional arguments
3492 # $text - The error message to write. If undefined, the text <<undef>> is written
3493 # $func - The function that produced the error (e.g. 'Games::Axmud::Session->start'). If
3494 # undefined, the function is not displayed
3495 #
3496 # Return values
3497 # 'undef'
3498  
3499 my ($self, $text, $func, $check) = @_;
3500  
3501 # Local variables
3502 my $msg;
3503  
3504 # Check for improper arguments
3505 if (defined $check) {
3506  
3507 return $axmud::CLIENT->writeImproper($self->_objClass . '->writeError', @_);
3508 }
3509  
3510 # If this object has a ->session IV, then we can find its default tab
3511 if (exists $self->{'session'} && $self->session && $self->session->defaultTabObj) {
3512  
3513 return $self->session->defaultTabObj->textViewObj->showError($text, $func);
3514  
3515 # Otherwise, try the GA::Client's current session (the visible session in the last 'main'
3516 # window to receive focus)
3517 } elsif ($axmud::CLIENT->currentSession && $axmud::CLIENT->currentSession->defaultTabObj) {
3518  
3519 return $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showError(
3520 $text,
3521 $func,
3522 );
3523  
3524 } else {
3525  
3526 # Write to the terminal and the Client Console window, if possible
3527 if (! defined $text) {
3528  
3529 $text = "<<undef>>\n";
3530 }
3531  
3532 if ($func) {
3533 $msg = "ERROR: $func: $text";
3534 } else {
3535 $msg = "ERROR: $text";
3536 }
3537  
3538 $axmud::CLIENT->add_systemMsg('error', $msg);
3539 print $msg . "\n";
3540  
3541 return undef;
3542 }
3543 }
3544  
3545 sub writeWarning {
3546  
3547 # Can be called by anything
3548 # Passes a set of arguments to GA::Obj::TextView->showWarning. If it's not possible to
3549 # display a message in a 'main' window, writes to the terminal (and the Client Console
3550 # window, the next time it's opened)
3551 #
3552 # Expected arguments
3553 # (none besides $self)
3554 #
3555 # Optional arguments
3556 # $text - The warning message to write. If undefined, the text <<undef>> is written
3557 # $func - The function that produced the warning (e.g. 'Games::Axmud::Session->start').
3558 # If undefined, the function is not displayed
3559 #
3560 # Return values
3561 # 'undef'
3562  
3563 my ($self, $text, $func, $check) = @_;
3564  
3565 # Local variables
3566 my $msg;
3567  
3568 # Check for improper arguments
3569 if (defined $check) {
3570  
3571 return $axmud::CLIENT->writeImproper($self->_objClass . '->writeWarning', @_);
3572 }
3573  
3574 # If this object has a ->session IV, then we can find its default tab
3575 if (exists $self->{'session'} && $self->session && $self->session->defaultTabObj) {
3576  
3577 return $self->session->defaultTabObj->textViewObj->showWarning($text, $func);
3578  
3579 # Otherwise, try the GA::Client's current session (the visible session in the last 'main'
3580 # window to receive focus)
3581 } elsif ($axmud::CLIENT->currentSession && $axmud::CLIENT->currentSession->defaultTabObj) {
3582  
3583 return $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showWarning(
3584 $text,
3585 $func,
3586 );
3587  
3588 } else {
3589  
3590 # Write to the terminal and the Client Console window, if possible
3591 if (! defined $text) {
3592  
3593 $text = "<<undef>>\n";
3594 }
3595  
3596 if ($func) {
3597 $msg = "WARNING: $func: $text";
3598 } else {
3599 $msg = "WARNING: $text";
3600 }
3601  
3602 $axmud::CLIENT->add_systemMsg('warning', $msg);
3603 print $msg . "\n";
3604  
3605 return undef;
3606 }
3607 }
3608  
3609 sub writeDebug {
3610  
3611 # Can be called by anything
3612 # Passes a set of arguments to GA::Obj::TextView->showDebug. If it's not possible to
3613 # display a message in a 'main' window, writes to the terminal (and the Client Console
3614 # window, the next time it's opened)
3615 #
3616 # Expected arguments
3617 # (none besides $self)
3618 #
3619 # Optional arguments
3620 # $text - The debug message to write. If undefined, the text <<undef>> is written
3621 # $func - The function that produced the message (e.g. 'Games::Axmud::Session->start').
3622 # If undefined, the function is not displayed
3623 #
3624 # Return values
3625 # 'undef'
3626  
3627 my ($self, $text, $func, $check) = @_;
3628  
3629 # Local variables
3630 my $msg;
3631  
3632 # Check for improper arguments
3633 if (defined $check) {
3634  
3635 return $axmud::CLIENT->writeImproper($self->_objClass . '->writeDebug', @_);
3636 }
3637  
3638 # If this object has a ->session IV, then we can find its default tab
3639 if (exists $self->{'session'} && $self->session && $self->session->defaultTabObj) {
3640  
3641 return $self->session->defaultTabObj->textViewObj->showDebug($text, $func);
3642  
3643 # Otherwise, try the GA::Client's current session (the visible session in the last 'main'
3644 # window to receive focus)
3645 } elsif ($axmud::CLIENT->currentSession && $axmud::CLIENT->currentSession->defaultTabObj) {
3646  
3647 return $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showDebug(
3648 $text,
3649 $func,
3650 );
3651  
3652 } else {
3653  
3654 # Write to the terminal and the Client Console window, if possible
3655 if (! defined $text) {
3656  
3657 $text = "<<undef>>\n";
3658 }
3659  
3660 if ($func) {
3661 $msg = "DEBUG: $func: $text";
3662 } else {
3663 $msg = "DEBUG: $text";
3664 }
3665  
3666 $axmud::CLIENT->add_systemMsg('debug', $msg);
3667 print $msg . "\n";
3668  
3669 return undef;
3670 }
3671 }
3672  
3673 sub wd {
3674  
3675 # Convenience function; all arguments are passed directly to $self->writeDebug
3676 #
3677 # Expected arguments
3678 # (none besides $self)
3679 #
3680 # Optional arguments
3681 # $text - The debug message to write. If undefined, the text <<undef>> is written
3682 # $func - The function that produced the message (e.g. 'Games::Axmud::Session->start').
3683 # If undefined, the function is not displayed
3684 #
3685 # Return values
3686 # 'undef'
3687  
3688 my ($self, @args) = @_;
3689  
3690 return $self->writeDebug(@args);
3691 }
3692  
3693 sub writeImproper {
3694  
3695 # Can be called by anything
3696 # Passes a set of arguments to GA::Obj::TextView->showImproper. If it's not possible to
3697 # display a message there, writes to the terminal (and the Client Console window, the next
3698 # time it's opened)
3699 #
3700 # Expected arguments
3701 # $func - The function that produced the message (e.g. 'Games::Axmud::Session->start')
3702 #
3703 # Optional arguments
3704 # @args - A list of arguments passed to the calling function. If no arguments were
3705 # passed, an empty list
3706 #
3707 # Return values
3708 # 'undef'
3709  
3710 my ($self, $func, @args) = @_;
3711  
3712 # Local variables
3713 my $msg;
3714  
3715 # Check for improper arguments
3716 if (! defined $func) {
3717  
3718 # This function mustn't call itself, so write something to the terminal and the Client
3719 # Console window, if possible
3720 $msg = "ERROR: Recursive improper arguments call from $func";
3721  
3722 $axmud::CLIENT->add_systemMsg('improper', $msg);
3723 print $msg . "\n";
3724  
3725 return undef;
3726 }
3727  
3728 # Always display improper arguments error messages in the current session's default tab
3729 if ($axmud::CLIENT->currentSession && $axmud::CLIENT->currentSession->defaultTabObj) {
3730  
3731 return $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showImproper(
3732 $func,
3733 @args,
3734 );
3735  
3736 } else {
3737  
3738 # Some of the values in @args might be 'undef'; these need to be replaced by some text
3739 # that can actually be displayed
3740 foreach my $arg (@args) {
3741  
3742 if (! defined $arg) {
3743  
3744 $arg = "<<undef>>\n";
3745 }
3746 }
3747  
3748 # Write to the terminal and the Client Console window, if possible
3749 $msg = "IMPROPER ARGUMENTS: $func() " . join (" ", @args);
3750  
3751 $axmud::CLIENT->add_systemMsg('improper', $msg);
3752 print $msg . "\n";
3753  
3754 return undef;
3755 }
3756 }
3757  
3758 sub debugBreak {
3759  
3760 # Can be called by anything
3761 # Opens a 'dialogue' window, which effectively halts execution until the window is closed
3762 #
3763 # Expected arguments
3764 # (none besides $self)
3765 #
3766 # Optional arguments
3767 # $title - The window title. If undefined, a generic title is set
3768 # $msg - The message to show. If undefined, a generic message is shown
3769 #
3770 # Return values
3771 # 'undef' on improper arguments or if the 'dialogue' window can't be opened
3772 # 1 otherwise
3773  
3774 my ($self, $title, $msg, $check) = @_;
3775  
3776 # Check for improper arguments
3777 if (defined $check) {
3778  
3779 return $axmud::CLIENT->writeImproper($self->_objClass . '->debugBreak', @_);
3780 }
3781  
3782 if (! $title) {
3783  
3784 $title = $axmud::SCRIPT . ' debug';
3785 }
3786  
3787 if (! $msg) {
3788  
3789 $msg = 'This is a debug message';
3790 }
3791  
3792 # Open the 'dialogue' window, using the current session's 'main' window as the parent window
3793 # (if there is one)
3794 if ($axmud::CLIENT->mainWin) {
3795  
3796 $axmud::CLIENT->mainWin->showMsgDialogue(
3797 $title,
3798 'info',
3799 $msg,
3800 'ok',
3801 );
3802  
3803 return 1;
3804  
3805 } else {
3806  
3807 return $self->writeError(
3808 'Can\'t open debug \'dialogue\' window when no \'main\' windows are open',
3809 $self->_objClass . '->debugBreak',
3810 );
3811 }
3812 }
3813  
3814 sub writePerlError {
3815  
3816 # Called by code in axmud.pl
3817 # After trapping a Perl error, display the error in a 'main' window. If it's not possible to
3818 # display a message there, write to the terminal (and the Client Console window, the next
3819 # time it's opened)
3820 #
3821 # Expected arguments
3822 # @list - One or more lines of text that comprise the Perl error message
3823 #
3824 # Return values
3825 # 'undef'
3826  
3827 my ($self, @list) = @_;
3828  
3829 # Local variables
3830 my $msg;
3831  
3832 # (No improper arguments to check)
3833  
3834 # We don't know which session generated the error, so display the error message in the
3835 # current session's tab
3836 if (
3837 $axmud::CLIENT->debugTrapErrorFlag
3838 && $axmud::CLIENT->currentSession
3839 && $axmud::CLIENT->currentSession->defaultTabObj
3840 ) {
3841 foreach my $string (@list) {
3842  
3843 # GA::Obj::TextView->showError is not expecting any newline characters, so remove
3844 # them
3845 foreach my $line (split(/\n/, $string)) {
3846  
3847 $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showError($line);
3848 }
3849 }
3850  
3851 } else {
3852  
3853 # Write to the terminal and the Client Console window, if possible
3854 $msg = "PERL ERROR: " . join("\n", @list);
3855  
3856 $axmud::CLIENT->add_systemMsg('error', $msg);
3857 print $msg . "\n";
3858  
3859 return undef;
3860 }
3861  
3862 return undef;
3863 }
3864  
3865 sub writePerlWarning {
3866  
3867 # Called by code in axmud.pl
3868 # After trapping a Perl warning, display the warning in a 'main' window. If it's not
3869 # possible to display a message there, write to the terminal (and the Client Console
3870 # window, the next time it's opened)
3871 #
3872 # Expected arguments
3873 # @list - One or more lines of text that comprise the Perl warning message
3874 #
3875 # Return values
3876 # 'undef'
3877  
3878 my ($self, @list) = @_;
3879  
3880 # Local variables
3881 my $msg;
3882  
3883 # (No improper arguments to check)
3884  
3885 # We don't know which session generated the warning, so display the warning message in the
3886 # current session's tab
3887 if (
3888 $axmud::CLIENT->debugTrapErrorFlag
3889 && $axmud::CLIENT->currentSession
3890 && $axmud::CLIENT->currentSession->defaultTabObj
3891 ) {
3892 foreach my $string (@list) {
3893  
3894 # GA::Obj::TextView->showWarning is not expecting any newline character, so remove
3895 # them
3896 foreach my $line (split(/\n/, $string)) {
3897  
3898 $axmud::CLIENT->currentSession->defaultTabObj->textViewObj->showWarning($line);
3899 }
3900 }
3901  
3902 } else {
3903  
3904 # Write to the terminal and the Client Console window, if possible
3905 $msg = "PERL WARNING: " . join("\n", @list);
3906  
3907 $axmud::CLIENT->add_systemMsg('warning', $msg);
3908 print $msg . "\n";
3909  
3910 return undef;
3911 }
3912  
3913 return undef;
3914 }
3915  
3916 sub showList {
3917  
3918 # Debugging function
3919 # Displays the contents of a list, numbered
3920 #
3921 # Expected arguments
3922 # $num - A Perl line number to display
3923 # @list - The list to display
3924 #
3925 # Return values
3926 # 1
3927  
3928 my ($self, $num, @list) = @_;
3929  
3930 # Local variables
3931 my $count;
3932  
3933 # (This is a debugging function, so no need to check for improper arguments)
3934  
3935 # Display header
3936 if (! $num) {
3937  
3938 # Forgot to specify it...
3939 $num = '?';
3940 }
3941  
3942 $self->writeDebug('START of list (line ' . $num . ', size: ' . @list . ')');
3943  
3944 # Display list
3945 $count = -1;
3946 foreach my $item (@list) {
3947  
3948 $count++;
3949  
3950 if (defined $item) {
3951 $self->writeDebug(' ' . $count . ': ' . $item);
3952 } else {
3953 $self->writeDebug(' ' . $count . ': <undef>');
3954 }
3955 }
3956  
3957 # Display footer
3958 $self->writeDebug('END of list');
3959  
3960 return 1;
3961 }
3962  
3963 sub showHash {
3964  
3965 # Debugging function
3966 # Displays contents of a hash
3967 #
3968 # Expected arguments
3969 # $num - A line number to display
3970 # %hash - The hash to display
3971 #
3972 # Return values
3973 # 1
3974  
3975 my ($self, $num, %hash) = @_;
3976  
3977 # (This is a debugging function, so no need to check for improper arguments)
3978  
3979 # Display header
3980 if (! $num) {
3981  
3982 # Forgot to specify it...
3983 $num = '?';
3984 }
3985  
3986 $self->writeDebug('START of hash (line ' . $num . ')');
3987  
3988 # Display hash
3989 foreach my $key (keys %hash) {
3990  
3991 if (defined $hash{$key}) {
3992 $self->writeDebug(' key: ' . $key . ' value: ' . $hash{$key});
3993 } else {
3994 $self->writeDebug(' key: ' . $key . ' value: <<UNDEF>>');
3995 }
3996 }
3997  
3998 # Display footer
3999 $self->writeDebug('END of hash');
4000  
4001 return 1;
4002 }
4003  
4004 sub getMethodRef {
4005  
4006 # Convenience function for obtaining a function reference to a method (i.e. a function
4007 # within an OOP object). The Perl code is a bit tricky, so this function can be used to
4008 # simplify things a bit
4009 #
4010 # Example call:
4011 # $self->getMethodRef('entryCallback')
4012 #
4013 # Expected arguments
4014 # $funcName - The name of a function, which must be a function in $self
4015 #
4016 # Return values
4017 # 'undef' on improper arguments
4018 # Otherwise returns a function reference
4019  
4020 my ($self, $funcName, $check) = @_;
4021  
4022 # Local variables
4023 my $funcRef;
4024  
4025 # Check for improper arguments
4026 if (! defined $funcName || defined $check) {
4027  
4028 return $axmud::CLIENT->writeImproper($self->_objClass . '->getMethodRef', @_);
4029 }
4030  
4031 $funcRef = sub { $self->$funcName(@_) };
4032  
4033 return $funcRef;
4034 }
4035  
4036 ##################
4037 # Accessors - get
4038  
4039 # There are five standard IVs for every Axmud Perl object
4040  
4041 # A name for the object (might store the same value as the ->name IV, if there is one). Not
4042 # used for anything important
4043 sub _objName
4044 { $_[0]->{_objName} }
4045  
4046 # The class into which the object has been blessed (usually the same as ref($self) )
4047 sub _objClass
4048 { $_[0]->{_objClass} }
4049  
4050 # The parent GA::Obj::File. Value matches one of the standard file object types (currently
4051 # 'config', 'otherprof', 'worldmodel', 'tasks', 'scripts', 'contacts', 'dicts', 'toolbar',
4052 # 'usercmds', 'zonemaps', 'winmaps', 'tts' or, for 'worldprof' file objects, the name of the
4053 # world profile). Very important; used to set parent file object's ->modifyFlag
4054 sub _parentFile
4055 { $_[0]->{_parentFile} }
4056  
4057 # The 'otherprof' and 'worldmodel' file objects aren't stored in the GA::Client - where anything
4058 # can look them up - but in GA::Session objects for which they have been loaded. In order to
4059 # set the ->modifyFlag for these file objects, this value matches the name of the current
4060 # world profile for the session(s). Set to 'undef' for other types of file object
4061 sub _parentWorld
4062 { $_[0]->{_parentWorld} }
4063  
4064 # A flag set to TRUE if this object's IVs are 'private' - which means that other objects can
4065 # read the IVs, but cannot set them directly; instead they have to call a 'get' accessor. Set
4066 # to FALSE if IVs can be set directly with calls like $obj->ivPoke(iv_name, new_value)
4067 sub _privFlag
4068 { $_[0]->{_privFlag} }
4069  
4070 ##################
4071 # Accessors - set
4072 }
4073  
4074 =pod
4075  
4076 =head1 NAME
4077  
4078 Games::Axmud - Axmud, a modern Multi-User Dungeon (MUD) client written in Perl5
4079 / Gtk3
4080  
4081 =head1 SYNOPSIS
4082  
4083 Axmud is known to work on MS Windows, Linux and *BSD. It might be possible to
4084 install it on other systems such as MacOS, but the authors have not been able to
4085 confirm this yet.
4086  
4087 After installation (see the README.rst file), visually-impaired users can run
4088 this script
4089  
4090 baxmud.pl
4091  
4092 Other users can run this script
4093  
4094 axmud.pl
4095  
4096 Using either script, you can specify a world to which Axmud connects immediately
4097  
4098 axmud.pl empiremud.net 4000
4099  
4100 If you omit the port number, Axmud connects using the generic port 23
4101  
4102 axmud.pl elephant.org
4103  
4104 If a world profile already exists, you can specify its name instead
4105  
4106 axmud.pl cryosphere
4107  
4108 You can force Axmud to use a particular text-to-speech engine by adding the
4109 engine's name to the end of those commands. This overrides (almost) all other
4110 text-to-speech settings.
4111  
4112 Acceptable engine names are 'espeak', 'esng' (for espeak-ng), 'flite' (for
4113 Festival Lite), 'festival', 'swift' and 'none' (for the dummy engine, which
4114 produces no sound). For example:
4115  
4116 baxmud.pl empiremud.net 4000 esng
4117 axmud.pl cryosphere festival
4118  
4119 Note that on MS Windows, Flite is not supported, and other speech engines are
4120 assumed to be installed in their default locations.
4121  
4122 =head1 DESCRIPTION
4123  
4124 Axmud is a modern Multi-User Dungeon (MUD) client written in Perl 5 / GTK 3.
4125 Its features include:
4126  
4127 - Telnet, SSH and SSL connections
4128 - ANSI/xterm/truecolour/OSC/RGB colours
4129 - Full support for all major MUD protocols, including MXP and GMCP (with partial
4130 Pueblo support)
4131 - Partial VT100 emulation
4132 - Class-based triggers, aliases, macros, timers and hooks
4133 - Graphical automapper
4134 - Over 100 pre-configured worlds
4135 - Multiple approaches to scripting
4136 - Fully customisable from top to bottom, using the command line or the extensive
4137 GUI interface
4138 - Native support for visually-impaired users
4139  
4140 =head1 AUTHOR
4141  
4142 A S Lewis <aslewis@cpan.org>
4143  
4144 =head1 COPYRIGHT
4145  
4146 Copyright (C) 2011-2024 A S Lewis
4147  
4148 This program is free software: you can redistribute it and/or modify it under
4149 the terms of the GNU General Public License as published by the Free Software
4150 Foundation, either version 3 of the License, or (at your option) any later
4151 version.
4152  
4153 This program is distributed in the hope that it will be useful, but WITHOUT ANY
4154 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
4155 PARTICULAR PURPOSE. See the GNU General Public License for more details.
4156  
4157 You should have received a copy of the GNU General Public License along with
4158 this program. If not, see <http://www.gnu.org/licenses/>.
4159  
4160 =cut
4161  
4162 # Package must return a true value
4163 1
« blib/lib/auto/share/dist/Games-Axmud/plugins/zmptest.pm ↑ Summary