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

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 80 CC 4 SCAR 20.2
CC
4
Cov
0%
new
20.0
name
2.0
longName
2.0
CRAP 7.5
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::BasicWorld
16 # Stores the basic mudlist (containing many more worlds than Axmud's list of pre-configured worlds)
17  
18 { package Games::Axmud::Obj::BasicWorld;
19  
20 use strict;
21 use warnings;
22 # use diagnostics;
23  
24 use Glib qw(TRUE FALSE);
25  
26 our @ISA = qw(Games::Axmud);
27  
28 ##################
29 # Constructors
30  
31 sub new {
32  
33 # Called by GA::Client->loadBasicWorlds
34 # Creates a new instance of the basic world object
35 #
36 # Expected arguments
37 # $name - World's short name, matching GA::Profile::World->name (max 16 chars,
38 # containing A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets
39 # acceptable. Must not exist as a key in the global hash of reserved
40 # names, $axmud::CLIENT->constReservedHash)
41 # $longName - World's long name, matching GA::Profile::World->longName (suggested max
42 # length of 32 chars)
43 # $host - DNS or IP address
44 # $port - Port
45 # $adultFlag - Flag set to TRUE for worlds with primarily adult (sexual) content, FALSE
46 # otherwise
47 # $language - String representing the dictionary language (matching
48 # GA::Obj::Dict->language, e.g. 'English', 'Francais', 'Deutsch')
49 #
50 # Return values
51 # 'undef' on improper arguments or if any arguments are invalid
52 # Blessed reference to the newly-created object on success
53  
54 my ($class, $name, $longName, $host, $port, $adultFlag, $language, $check) = @_;
55  
56 # Check for improper arguments
57 if (
58 ! defined $class || ! defined $name || ! defined $longName || ! defined $host
59 || ! defined $port || ! defined $adultFlag || ! defined $language || defined $check
60 ) {
61 return $axmud::CLIENT->writeImproper($class . '->new', @_);
62 }
63  
64 # Check that $shortName is valid
65 if (! $axmud::CLIENT->nameCheck($name, 16)) {
66  
67 return $axmud::CLIENT->writeError(
68 'Registry naming error: invalid name \'' . $name . '\'',
69 $class . '->new',
70 );
71 }
72  
73 # Flag must be TRUE or FALSE
74 if (! $adultFlag) {
75 $adultFlag = FALSE;
76 } else {
77 $adultFlag = TRUE;
78 }
79  
80 # Setup
81 my $self = {
82 _objName => $name,
83 _objClass => $class,
84 _parentFile => undef, # No parent file object
85 _parentWorld => undef,
86 _privFlag => TRUE, # All IVs are private
87  
88 # IVs
89 # ---
90  
91 # World's short name, matching GA::Profile::World->name (max 16 chars, containing
92 # A-Za-z0-9_ - 1st char can't be number, non-Latin alphabets acceptable. Must not
93 # exist as a key in the global hash of reserved names,
94 # $axmud::CLIENT->constReservedHash)
95 name => $name,
96 # World's long name, matching GA::Profile::World->longName (suggested max length of 32
97 # chars)
98 longName => $longName,
99 # DNS or IP address
100 host => $host,
101 # Port
102 port => $port,
103 # Flag set to TRUE for worlds with primarily adult (sexual) content, FALSE otherwise
104 adultFlag => $adultFlag,
105 # String representing the dictionary language (matching GA::Obj::Dict->language, e.g.
106 # 'English', 'Francais', 'Deutsch'
107 language => $language,
108 };
109  
110 # Bless the object into existence
111 bless $self, $class;
112 return $self;
113 }
114  
115 ##################
116 # Methods
117  
118 ##################
119 # Accessors - set
120  
121 ##################
122 # Accessors - get
123  
124 sub name
125 { $_[0]->{name} }
126 sub longName
127 { $_[0]->{longName} }
128 sub host
129 { $_[0]->{host} }
130 sub port
131 { $_[0]->{port} }
132 sub adultFlag
133 { $_[0]->{adultFlag} }
134 sub language
135 { $_[0]->{language} }
136 }
137  
138 # Package must return a true value
139 1