blib/lib/Net/Intermapper/Vertice.pm

filter: Statementstmt 60.3% 38 / 63 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 56.1% 46 / 82 CC 7 SCAR 22.5
CC
7
Cov
55%
toCSV
20.0
header
12.0
toXML
6.0
CRAP 9.5
« blib/lib/Net/Intermapper/User.pm ↑ Summary blib/lib/Net/Intermapper/Interface.pm »
1 package Net::Intermapper::Vertice;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 1 ▶ use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @HEADERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ $VERSION = '0.03';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 @ISA = qw(Exporter);
10 1 @EXPORT = qw();
11 1 @EXPORT_OK = qw();
12 1 %EXPORT_TAGS = ();
13
14 1 @HEADERS = qw(MapName Id Name Color FontName FontSize FontStyle Label LabelPosition LabelTemplate LabelVisible MapId Origin Shape VantagePoint XCoordinate YCoordinate VertexId);
15 };
16  
17 # MOOSE!
18  
19 1 has 'MapName' => (
20 is => 'rw',
21 isa => 'Str',
22 );
23  
24 1 has 'Id' => (
25 is => 'rw',
26 isa => 'Str',
27 );
28  
29 1 has 'Name' => (
30 is => 'rw',
31 isa => 'Str',
32 );
33  
34 1 has 'Color' => (
35 is => 'rw',
36 isa => 'Str',
37 );
38  
39 1 has 'FontName' => (
40 is => 'rw',
41 isa => 'Str',
42 );
43  
44 1 has 'FontSize' => (
45 is => 'rw',
46 isa => 'Str',
47 );
48  
49 1 has 'FontStyle' => (
50 is => 'rw',
51 isa => 'Str',
52 );
53  
54 1 has 'Label' => (
55 is => 'rw',
56 isa => 'Str',
57 );
58  
59 1 has 'LabelPosition' => (
60 is => 'rw',
61 isa => 'Str',
62 );
63  
64 1 has 'LabelTemplate' => (
65 is => 'rw',
66 isa => 'Str',
67 );
68  
69 1 has 'LabelVisible' => (
70 is => 'rw',
71 isa => 'Str',
72 );
73  
74 1 has 'MapId' => (
75 is => 'rw',
76 isa => 'Str',
77 );
78  
79 1 has 'Origin' => (
80 is => 'rw',
81 isa => 'Str',
82 );
83  
84 1 has 'Shape' => (
85 is => 'rw',
86 isa => 'Str',
87 );
88  
89 1 has 'VantagePoint' => (
90 is => 'rw',
91 isa => 'Str',
92 );
93  
94 1 has 'XCoordinate' => (
95 is => 'rw',
96 isa => 'Str',
97 );
98  
99 1 has 'YCoordinate' => (
100 is => 'rw',
101 isa => 'Str',
102 );
103  
104 1 has 'VertexId' => (
105 is => 'rw',
106 isa => 'Str',
107 );
108  
109 # No Moose
110
111 sub toXML
112 0 ▶{ my $self = shift;
Subroutine toXML: not called CC=2 SCAR=17.9
Pod documented
113 0 my $id = $self->Id;
114 0 my $result = "";
115
116 0 ▶ if ($id) { $result = " <id>$id</id>\n"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($id) 0 0 0
117 0 return $result;
118 }
119  
120 sub toCSV
121 0 ▶{ my $self = shift;
Subroutine toCSV: not called CC=4 SCAR=30.0
Pod documented
122 0 my $id = $self->Id;
123 0 my $result = "";
124 0 my @attributes = $self->meta->get_all_attributes;
125 0 my %attributes = ();
126 0 for my $attribute (@attributes)
127 0 ▶ { $attributes{$attribute->name} = $attribute->get_value($self) || "";
Condition0%0/2
$attribute->get_value($self) || ''
l!l
00
MC/DC0%0/1
$attribute->get_value($self) || ''
$attribute->get_value($self)
Truth table0%0/2
A
A= $attribute->get_value($self)
Aresult
11
00
128 }
129 0 for my $key (@HEADERS)
130 0 { $result .= $attributes{$key}.","; }
131 0 chop $result; # Remove the comma of the last field
132 0 $result .= "\r\n";
133 0 return $result;
134 }
135  
136 sub header
137 0 ▶{ my $self = shift;
Subroutine header: not called CC=3 SCAR=24.8
Pod documented
138 0 ▶ my $format = shift || "";
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
139 0 my $header = "# format=$format table=vertices fields=";
140 0 for my $key (@HEADERS)
141 0 { $header .= $key.","; }
142 0 $header .= "\r\n";
143 0 return $header;
144 }
145
146 =pod
147
148 =head1 NAME
149  
150 Net::Intermapper::Vertice - Interface with the HelpSystems Intermapper HTTP API - Vertices
151  
152 =head1 SYNOPSIS
153  
154 use Net::Intermapper;
155 my $intermapper = Net::Intermapper->new(hostname=>"10.0.0.1", username=>"admin", password=>"nmsadmin");
156 # Options:
157 # hostname - IP or hostname of Intermapper 5.x and 6.x server
158 # username - Username of Administrator user
159 # password - Password of user
160 # ssl - SSL enabled (1 - default) or disabled (0)
161 # port - TCP port for querying information. Defaults to 8181
162 # modifyport - TCP port for modifying information. Default to 443
163 # cache - Boolean to enable smart caching or force network queries
164  
165 my %users = $intermapper->users;
166 my $users_ref = $intermapper->users;
167 # Retrieve all users from Intermapper, Net::Intermapper::User instances
168 # Returns hash or hashref, depending on context
169
170 my %devices = $intermapper->devices;
171 my $devices_ref = $intermapper->devices;
172 # Retrieve all devices from Intermapper, Net::Intermapper::Device instances
173 # Returns hash or hashref, depending on context
174  
175 my %maps = $intermapper->maps;
176 my $maps_ref = $intermapper->maps;
177 # Retrieve all maps from Intermapper, Net::Intermapper::Map instances
178 # Returns hash or hashref, depending on context
179  
180 my %interfaces = $intermapper->interfaces;
181 my $interfaces_ref = $intermapper->interfaces;
182 # Retrieve all interfaces from Intermapper, Net::Intermapper::Interface instances
183 # Returns hash or hashref, depending on context
184  
185 my %vertices = $intermapper->vertices;
186 my $vertices_ref = $intermapper->vertices;
187 # Retrieve all vertices from Intermapper, Net::Intermapper::Vertice instances
188 # Returns hash or hashref, depending on context
189  
190 my $user = $intermapper->users->{"admin"};
191
192 # Each class will generate specific header. These are typically only for internal use but are compliant to the import format Intermapper uses.
193 print $user->header;
194 print $device->header;
195 print $map->header;
196 print $interface->header;
197 print $vertice->header;
198  
199 print $user->toTAB;
200 print $device->toXML; # This one is broken still!
201 print $map->toCSV;
202 # Works on ALL subclasses
203 # Produce human-readable output of each record in the formats Intermapper supports
204
205 my $user = Net::Intermapper::User->new(Name=>"testuser", Password=>"Test12345");
206 my $response = $intermapper->create($user);
207 # Create new user
208 # Return value is HTTP::Response object
209
210 my $device = Net::Intermapper::Device->new(Name=>"testDevice", MapName=>"TestMap", MapPath=>"/TestMap", Address=>"10.0.0.1");
211 my $response = $intermapper->create($device);
212 # Create new device
213 # Return value is HTTP::Response object
214  
215 $user->Password("Foobar123");
216 my $response = $intermapper->update($user);
217 # Update existing user
218 # Return value is HTTP::Response object
219  
220 my $user = $intermapper->users->{"bob"};
221 my $response = $intermapper->delete($user);
222 # Delete existing user
223 # Return value is HTTP::Response object
224  
225 my $device = $intermapper->devices->{"UniqueDeviceID"};
226 my $response = $intermapper->delete($device);
227 # Delete existing device
228 # Return value is HTTP::Response object
229  
230 my $users = { "Tom" => $tom_user, "Bob" => $bob_user };
231 $intermapper->users($users);
232 # At this point, there is no real reason to do this as update, create and delete work with explicit arguments.
233 # But it can be done with users, devices, interfaces, maps and vertices
234 # Pass a hashref to each method. This will NOT affect the smart-caching (only explicit calls to create, update and delete do this - for now).
235
236 =head1 USAGE
237
238 =over 3
239  
240 =item new
241  
242 Class constructor. Returns object of Net::Intermapper::Vertice on succes. Attributes are:
243  
244 =over 5
245  
246 =item MapName (read-only)
247  
248 Name of the map file containing the vertex.
249  
250 =item Id (read-only)
251  
252 A unique, persistent identifier for this vertex instance. The id will be unique across all maps on a single InterMapper server. This value is used for lookups in the C<users> method in L<Net::Intermapper>.
253  
254 =item Name (read-only)
255  
256 The name of the vertex. The name is the first non-empty line in a device or network's label on a map.
257  
258 =item Color (read-write)
259  
260 Color (valid names: white, black, red, orange, yellow, blue, green, brown)
261  
262 =item FontName (read-write)
263  
264 Font name, eg. Bodoni MT
265  
266 =item FontSize (read-write)
267  
268 Font size in points.
269  
270 =item FontStyle (read-write)
271  
272 Font style (bold, italic, plain)
273  
274 =item Label (read-only)
275  
276 Vertex label.
277  
278 =item LabelPosition (read-write)
279  
280 Label position. Valid values are topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
281  
282 =item LabelTemplate (read-write)
283  
284 Vertex label template.
285  
286 =item LabelVisible (read-write)
287  
288 True if the vertex label is visible (only used when the device is represented by an icon)
289  
290 =item MapId (read-only)
291  
292 The unique Id of the map file containing the vertex.
293  
294 =item Origin (read-write)
295  
296 The origin determines whether the vertex coordinates are relative to the center or one of the sides of the vertex. Valid values: center, top, left, right, botom, topleft, topright, bottomright, bottomleft.
297  
298 =item Shape (read-write)
299  
300 Vertex shape (rect, oval, wire, cloud, text, or icon name).
301  
302 =item VantagePoint (read-write)
303  
304 True if the vertex is a vantage point of the graph
305  
306 =item XCoordinate (read-write)
307  
308 Horizontal map coordinate, the positive direction is to the right.
309  
310 =item YCoordinate (read-write)
311  
312 Vertical map coordinate, the positive direction is to the bottom.
313  
314 =item VertexId (read-only)
315  
316 The Vertex Id of the vertex. Corresponds to the device with a matching VertexID in the devices table.
317  
318 =back
319  
320 =over 3
321  
322 =item header
323  
324 Returns the C<directive> aka data header required by the Intermapper API to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
325  
326 =back
327  
328 =over 3
329  
330 =item toTAB
331  
332 Returns the object data formatted in TAB delimited format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
333  
334 =back
335  
336 =over 3
337  
338 =item toCSV
339  
340 Returns the object data formatted in Comma Separated delimited format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
341  
342 =back
343  
344 =over 3
345  
346 =item toXML
347  
348 Returns the object data formatted in XML format. Used in combination with the C<header> and the C<format> method in L<Net::Intermapper> to perform CRUD actions. This is handled through the C<create>, C<update> and C<delete> method and should not really be used.
349  
350 =back
351  
352 =over 3
353  
354 =item mode
355  
356 Internal method to properly format the data and header for CRUD actions. Typically not used.
357  
358 =back
359  
360 =item $ERROR
361  
362 NEEDS TO BE ADDED
363  
364 This variable will contain detailed error information.
365
366 =back
367  
368 =head1 REQUIREMENTS
369  
370 For this library to work, you need an instance with Intermapper (obviously) or a simulator like L<Net::Intermapper::Mock>.
371  
372 =over 3
373  
374 =item L<Moose>
375  
376 =item L<IO::Socket::SSL>
377  
378 =item L<LWP::UserAgent>
379  
380 =item L<XML::Simple>
381  
382 =item L<MIME::Base64>
383  
384 =item L<URI::Escape>
385  
386 =item L<Text::CSV_XS>
387  
388 =back
389  
390 =head1 BUGS
391  
392 None yet
393  
394 =head1 SUPPORT
395  
396 None yet :)
397  
398 =head1 AUTHOR
399  
400 Hendrik Van Belleghem
401 CPAN ID: BEATNIK
402 hendrik.vanbelleghem@gmail.com
403  
404 =head1 COPYRIGHT
405  
406 This program is free software licensed under the...
407  
408 The General Public License (GPL)
409 Version 2, June 1991
410  
411 The full text of the license can be found in the
412 LICENSE file included with this module.
413  
414  
415 =head1 SEE ALSO
416  
417 L<http://download.intermapper.com/docs/UserGuide/Content/09-Reference/09-05-Advanced_Importing/the_directive_line.htm>
418 L<http://download.intermapper.com/schema/imserverschema.html>
419  
420 =cut
421  
422 #################### main pod documentation end ###################
423 1 __PACKAGE__->meta->make_immutable();
424  
425 1 1;
426 # The preceding line will help the module return a true value
« blib/lib/Net/Intermapper/User.pm ↑ Summary blib/lib/Net/Intermapper/Interface.pm »