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

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 104 CC 2 SCAR 8.6
CC
2
Cov
0%
new
6.0
number
2.0
textViewObj
2.0
CRAP 2.4
1 # Copyright (C) 2011-2024 A S Lewis
2 #
3 # This program is free software: you can redistribute it and/or modify it under the terms of the GNU
4 # General Public License as published by the Free Software Foundation, either version 3 of the
5 # License, or (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
8 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License along with this program. If not,
12 # see <http://www.gnu.org/licenses/>.
13 #
14 #
15 # Games::Axmud::Obj::Link
16 # Stores details about a clickable link in a Gtk3::TextView, retrieved when the user clicks the link
17  
18 { package Games::Axmud::Obj::Link;
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::Session->processMxpLinkElement, ->processMxpSendElement and
34 # GA::Obj::TextView->add_link
35 # Creates a new instance of the link object, which stores details about a clickable link in
36 # a window, retrieved when the user clicks the link.
37 # Also used for MXP clickable links (in <A>..</A> or <SEND>..</SEND> constructions)
38 #
39 # Expected arguments
40 # $number - Number for this link object, unique within the parent textview object
41 # (set to -1 when creating an incomplete link object, which isn't
42 # applied to the textview until the whole link has been processed,
43 # e.g. when called by GA::Session->processMxpLinkElement)
44 # $textViewObj - The parent textview object (GA::Obj::TextView)
45 # $lineNum - The line number for the Gtk3::TextBuffer line in which the link
46 # appears (doesn't necessarily match the GA::Session's display buffer
47 # line numbers)
48 # $posn - The position of the first character of the link (first character on
49 # the line is position 0)
50 # $type - The type of link: 'www', 'mail', 'telnet', 'ssh', 'ssl', 'cmd',
51 # 'image' (or 'other' when the clickable text is empty)
52 #
53 # Return values
54 # 'undef' on improper arguments
55 # Blessed reference to the newly-created object on success
56  
57 my ($class, $number, $textViewObj, $lineNum, $posn, $type, $check) = @_;
58  
59 # Check for improper arguments
60 if (
61 ! defined $class || ! defined $number || ! defined $textViewObj || ! defined $lineNum
62 || ! defined $posn || ! defined $type || defined $check
63 ) {
64 return $axmud::CLIENT->writeImproper($class . '->new', @_);
65 }
66  
67 # Setup
68 my $self = {
69 _objName => 'link_' . $number,
70 _objClass => $class,
71 _parentFile => $textViewObj->session->currentWorld->name,
72 _parentWorld => undef,
73 _privFlag => FALSE, # All IVs are public
74  
75 # IVs
76 # ---
77  
78 # Number for this link object, unique within the parent textview object (set to -1 when
79 # creating an incomplete link object, which isn't applied to the textview until the
80 # whole link has been processed, e.g. when called by
81 # GA::Session->processMxpLinkElement)
82 number => $number,
83 # The parent textview object (GA::Obj::TextView)
84 textViewObj => $textViewObj,
85 # The line number for the Gtk3::TextBuffer line in which the link appears (doesn't
86 # necessarily match the GA::Session's display buffer line numbers)
87 lineNum => $lineNum,
88 # The position of the first character of the link (first character on the line is
89 # position 0)
90 posn => $posn,
91 # The type of link: 'www', 'mail', 'telnet', 'ssh', 'ssl', 'cmd', 'image' (or 'other'
92 # when $text is empty)
93 type => $type,
94  
95 # The link itself, e.g. 'http://deathmud.org'. Acceptable formats:
96 #
97 # (type = 'www')
98 # http://deathmud.org - a URL opened by GA::Client->browserCmd (anything
99 # matching GA::Client->constUrlRegex)
100 # deathmud.org - a URL opened by GA::Client->browserCmd (anything
101 # matching GA::Client->constShortUrlRegex)
102 #
103 # (type = 'mail')
104 # mailto:god@deathmud.org - an email sent by GA::Client->emailCmd
105 # admin@deathmud.org - an email sent by GA::Client->emailCmd
106 #
107 # ($type = 'telnet')
108 # telnet://deathmud.org:6666 - a new connection to a world, using telnet
109 # telnet://deathmud.org - a new connection to a world, port 23
110 #
111 # ($type = 'ssh')
112 # ssh://deathmud.org:6666 - a new connection to a world, using SSH
113 # ssh://deathmud.org - a new connection to a world, generic port
114 #
115 # ($type = 'ssl')
116 # ssl://deathmud.org:6666 - a new connection to a world, using SSL
117 # ssl://deathmud.org - a new connection to a world, generic port
118 #
119 # ($type = 'cmd')
120 # <any string> - a clickable world command (used with MXP)
121 #
122 # ($type = 'image')
123 # <any string> - a clickable image, which sends the string as a world
124 # command. If the string contains %x and/or %y, they
125 # are substituted for the x/y coordinates of the mouse
126 # click
127 #
128 # NB If 'undef' or an empty string , nothing happens when the user clicks the link
129 # link
130 # NB MXP links can't be ssh:// or ssl://
131 href => '',
132 # The clickable text displayed, e.g. 'Click here for DeathMud website'. If 'undef', an
133 # empty string is stored as an IV (in the expectation that it will be updated with
134 # some text). For non-MXP links, will be the same as $href. For images, 'undef' or an
135 # empty string (since there is no text)
136 text => '',
137 # A hint for this link, if specified ('undef' if not)
138 hint => undef,
139 # The expire name, for links that expire, if specified ('undef' if not)
140 expireName => undef,
141 # Flag set to TRUE when the link expires
142 expiredFlag => FALSE,
143  
144 # Flag set to TRUE if this is an MXP link, FALSE if it's a normal link
145 mxpFlag => FALSE,
146 # Flag set to TRUE if an MXP <SEND>..</SEND> specified PROMPT as one of its arguments
147 mxpPromptFlag => FALSE,
148 # Flag set to TRUE if an MXP link's corresponding command should be sent to the world
149 # invisibly, FALSE if it should be visible (or not) as any other world command is
150 mxpInvisFlag => FALSE,
151  
152 # Mode for Pueblo links, which are implemented in the same way as MXP <A> or <SEND>
153 # links, depending on arguments
154 # 'not_link' - not a Pueblo link, 'href_link' - <A HREF=...>, 'cmd_link'
155 # - <A XCH_CMD...>
156 puebloMode => 'not_link',
157  
158 # Flag set to TRUE if a popup menu should be created when the user clicks on this link
159 popupFlag => FALSE,
160 # When ->popupFlag is TRUE, $self->href is split into a list of world commands, and
161 # stored in this IV (but the value of $self->href remains unchanged)
162 popupCmdList => [],
163 # When ->popupFlag is TRUE, $self->hint is split into a list of menu items, and stored
164 # in this IV. If there is one more menu item than there are world commands, the
165 # first menu item (which is actually a hint) is removed and stored in $self->hint;
166 # otherwise $self->hint is set back to 'undef'
167 popupItemList => [],
168 };
169  
170 # Bless the object into existence
171 bless $self, $class;
172  
173 return $self;
174 }
175  
176 ##################
177 # Methods
178  
179 ##################
180 # Accessors - set
181  
182 ##################
183 # Accessors - get
184  
185 sub number
186 { $_[0]->{number} }
187 sub textViewObj
188 { $_[0]->{textViewObj} }
189 sub lineNum
190 { $_[0]->{lineNum} }
191 sub posn
192 { $_[0]->{posn} }
193 sub type
194 { $_[0]->{type} }
195  
196 sub href
197 { $_[0]->{href} }
198 sub text
199 { $_[0]->{text} }
200 sub hint
201 { $_[0]->{hint} }
202 sub expireName
203 { $_[0]->{expireName} }
204 sub expiredFlag
205 { $_[0]->{expiredFlag} }
206  
207 sub mxpFlag
208 { $_[0]->{mxpFlag} }
209 sub mxpPromptFlag
210 { $_[0]->{mxpPromptFlag} }
211 sub mxpInvisFlag
212 { $_[0]->{mxpInvisFlag} }
213  
214 sub puebloMode
215 { $_[0]->{puebloMode} }
216  
217 sub popupFlag
218 { $_[0]->{popupFlag} }
219 sub popupCmdList
220 { my $self = shift; return @{$self->{popupCmdList}}; }
221 sub popupItemList
222 { my $self = shift; return @{$self->{popupItemList}}; }
223 }
224  
225 # Package must return a true value
226 1