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.02';
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 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 print $user->header;
192 print $device->header;
193 print $map->header;
194 print $interface->header;
195 print $vertice->header;
196 # Generate 'directive' needed for manipulation. Mostly used internally.
197 # $user->mode("create"); # This changes the header fields
198 # $user->mode("update"); # This also changes the header fields
199 # Both are NOT needed when adding or updating a record
200 print $user->toTAB;
201 print $device->toXML;
202 print $map->toCSV;
203 # Works on ALL classes
204 # Produce human-readable output of each record.
205
206 my $user = Net::Intermapper::User->new(Name=>"testuser", Password=>"Test12345");
207 my $response = $intermapper->create($user);
208 # Create new user
209 # Return value is HTTP::Response object
210
211 my $device = Net::Intermapper::Device->new(Name=>"testDevice", MapName=>"TestMap", MapPath=>"/TestMap", Address=>"10.0.0.1");
212 my $response = $intermapper->create($device);
213 # Create new device
214 # Return value is HTTP::Response object
215  
216 $user->Password("Foobar123");
217 my $response = $intermapper->update($user);
218 # Update existing user
219 # Return value is HTTP::Response object
220  
221 my $user = $intermapper->users->{"bob"};
222 my $response = $intermapper->delete($user);
223 # Delete existing user
224 # Return value is HTTP::Response object
225  
226 my $device = $intermapper->devices->{"UniqueDeviceID"};
227 my $response = $intermapper->delete($device);
228 # Delete existing device
229 # Return value is HTTP::Response object
230  
231 my $users = { "Tom" => $tom_user, "Bob" => $bob_user };
232 $intermapper->users($users);
233 # At this point, there is no real reason to do this as update, create and delete work with explicit arguments.
234 # But it can be done with users, devices, interfaces, maps and vertices
235 # 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).
236
237 =head1 USAGE
238
239 =over 3
240  
241 =item new
242  
243 Class constructor. Returns object of Net::Intermapper::Vertice on succes. Attributes are:
244  
245 =over 5
246  
247 =item MapName (read-only)
248  
249 Name of the map file containing the vertex.
250  
251 =item Id (read-only)
252  
253 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>.
254  
255 =item Name (read-only)
256  
257 The name of the vertex. The name is the first non-empty line in a device or network's label on a map.
258  
259 =item Color (read-write)
260  
261 Color (valid names: white, black, red, orange, yellow, blue, green, brown)
262  
263 =item FontName (read-write)
264  
265 Font name, eg. Bodoni MT
266  
267 =item FontSize (read-write)
268  
269 Font size in points.
270  
271 =item FontStyle (read-write)
272  
273 Font style (bold, italic, plain)
274  
275 =item Label (read-only)
276  
277 Vertex label.
278  
279 =item LabelPosition (read-write)
280  
281 Label position. Valid values are topleft, top, topright, left, center, right, bottomleft, bottom, bottomright
282  
283 =item LabelTemplate (read-write)
284  
285 Vertex label template.
286  
287 =item LabelVisible (read-write)
288  
289 True if the vertex label is visible (only used when the device is represented by an icon)
290  
291 =item MapId (read-only)
292  
293 The unique Id of the map file containing the vertex.
294  
295 =item Origin (read-write)
296  
297 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.
298  
299 =item Shape (read-write)
300  
301 Vertex shape (rect, oval, wire, cloud, text, or icon name).
302  
303 =item VantagePoint (read-write)
304  
305 True if the vertex is a vantage point of the graph
306  
307 =item XCoordinate (read-write)
308  
309 Horizontal map coordinate, the positive direction is to the right.
310  
311 =item YCoordinate (read-write)
312  
313 Vertical map coordinate, the positive direction is to the bottom.
314  
315 =item VertexId (read-only)
316  
317 The Vertex Id of the vertex. Corresponds to the device with a matching VertexID in the devices table.
318  
319 =back
320  
321 =over 3
322  
323 =item header
324  
325 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.
326  
327 =back
328  
329 =over 3
330  
331 =item toTAB
332  
333 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.
334  
335 =back
336  
337 =over 3
338  
339 =item toCSV
340  
341 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.
342  
343 =back
344  
345 =over 3
346  
347 =item toXML
348  
349 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.
350  
351 =back
352  
353 =over 3
354  
355 =item mode
356  
357 Internal method to properly format the data and header for CRUD actions. Typically not used.
358  
359 =back
360  
361 =item $ERROR
362  
363 NEEDS TO BE ADDED
364  
365 This variable will contain detailed error information.
366
367 =back
368  
369 =head1 REQUIREMENTS
370  
371 For this library to work, you need an instance with Intermapper (obviously) or a simulator like L<Net::Intermapper::Mock>.
372  
373 =over 3
374  
375 =item L<Moose>
376  
377 =item L<IO::Socket::SSL>
378  
379 =item L<LWP::UserAgent>
380  
381 =item L<XML::Simple>
382  
383 =item L<MIME::Base64>
384  
385 =item L<URI::Escape>
386  
387 =back
388  
389 =head1 BUGS
390  
391 None yet
392  
393 =head1 SUPPORT
394  
395 None yet :)
396  
397 =head1 AUTHOR
398  
399 Hendrik Van Belleghem
400 CPAN ID: BEATNIK
401 hendrik.vanbelleghem@gmail.com
402  
403 =head1 COPYRIGHT
404  
405 This program is free software licensed under the...
406  
407 The General Public License (GPL)
408 Version 2, June 1991
409  
410 The full text of the license can be found in the
411 LICENSE file included with this module.
412  
413  
414 =head1 SEE ALSO
415  
416 L<http://download.intermapper.com/docs/UserGuide/Content/09-Reference/09-05-Advanced_Importing/the_directive_line.htm>
417 L<http://download.intermapper.com/schema/imserverschema.html>
418  
419 =cut
420  
421 #################### main pod documentation end ###################
422 1 __PACKAGE__->meta->make_immutable();
423  
424 1 1;
425 # The preceding line will help the module return a true value
« blib/lib/Net/Intermapper/User.pm ↑ Summary blib/lib/Net/Intermapper/Interface.pm »