File Coverage

blib/lib/IPC/XPA.pm
Criterion Covered Total %
statement 55 62 88.7
branch 18 38 47.3
condition 6 12 50.0
subroutine 13 14 92.8
pod 7 7 100.0
total 99 133 74.4


line stmt bran cond sub pod time code
1             package IPC::XPA;
2              
3             # ABSTRACT: Interface to the XPA messaging system
4              
5 1     1   271074 use strict;
  1         9  
  1         28  
6 1     1   5 use warnings;
  1         2  
  1         37  
7              
8             our $VERSION = '0.16';
9              
10 1     1   408 use parent 'DynaLoader';
  1         281  
  1         6  
11              
12             bootstrap IPC::XPA $VERSION;
13              
14 1     1   66 use Carp;
  1         2  
  1         47  
15              
16 1     1   465 use namespace::clean;
  1         10887  
  1         6  
17              
18              
19             # default attributes for Get, Set, Info, Access
20             my %def_attrs = ( max_servers => 1000, mode => {} );
21              
22             sub _flatten_mode {
23 14     14   34 my ( $mode ) = @_;
24              
25 14 100       14724 return q{} unless keys %$mode;
26              
27 2         6 join( q{,}, map { "$_=" . $mode->{$_} } keys %$mode );
  2         44  
28             }
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44              
45              
46              
47              
48              
49              
50              
51              
52              
53              
54              
55              
56              
57              
58             sub Open {
59 2     2 1 10640 my ( $class, $mode ) = @_;
60 2   33     38 $class = ref( $class ) || $class;
61              
62             # _Open will bless $xpa into the IPC::XPA class, but
63             # need to worry about inheritance.
64 2         15 my $xpa = _Open( _flatten_mode( $mode ) );
65 2         86 bless { xpa => $xpa }, $class;
66             }
67              
68              
69              
70              
71              
72              
73              
74              
75              
76              
77             sub Close {
78 2     2 1 10 my $xpa = shift;
79 2 50       100 _Close( $xpa->{xpa} ) if defined $xpa->{xpa};
80 2         166 undef $xpa->{xpa};
81             }
82              
83             sub DESTROY {
84 2     2   2880 $_[0]->Close;
85             }
86              
87              
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100              
101              
102              
103              
104              
105              
106              
107              
108              
109              
110              
111              
112              
113              
114              
115              
116              
117              
118              
119              
120              
121              
122              
123              
124              
125              
126              
127              
128              
129              
130              
131              
132              
133              
134              
135              
136              
137              
138              
139              
140              
141              
142              
143              
144              
145              
146              
147              
148              
149              
150             sub Get {
151 2     2 1 3810 my $obj = shift;
152              
153 2 50       17 my $attrs = 'HASH' eq ref $_[-1] ? pop @_ : {};
154              
155 2 50       9 @_ == 2
156             or croak( 'usage: IPC::XPA->Get( $template, $paramlist [,\%attrs]' );
157              
158 2         5 my ( $template, $paramlist ) = @_;
159              
160 2         7 my %attrs = ( %def_attrs, %$attrs );
161              
162             # if called as a class method (ref($obj) not defined)
163             # create an essentially NULL pointer for pass to XPAGet
164 2 50       17 my $xpa = ref( $obj ) ? $obj->{xpa} : nullXPA();
165              
166 2         7 _Get( $xpa, $template, $paramlist, _flatten_mode( $attrs{mode} ), $attrs{max_servers} );
167             }
168              
169              
170              
171              
172              
173              
174              
175              
176              
177              
178              
179              
180              
181              
182              
183              
184              
185              
186              
187              
188              
189              
190              
191              
192              
193              
194              
195              
196              
197              
198              
199              
200              
201              
202              
203              
204              
205              
206              
207              
208              
209              
210              
211              
212              
213              
214              
215              
216              
217              
218              
219              
220              
221              
222              
223              
224              
225              
226              
227              
228              
229              
230              
231              
232              
233              
234              
235              
236              
237              
238              
239              
240             sub Set {
241 3     3 1 3728 my $obj = shift;
242              
243 3 50       18 my $attrs = 'HASH' eq ref $_[-1] ? pop @_ : {};
244              
245 3 50 66     31 @_ == 2 || @_ == 3
246             or croak( 'usage: IPC::XPA->Set( $template, $paramlist [, [$buf],[\%attrs]]' );
247              
248 3         11 my $template = shift;
249 3         7 my $paramlist = shift;
250              
251 3         24 my %attrs = ( %def_attrs, %$attrs );
252              
253             # we want a reference to the data to avoid copying it.
254             # if it's already a reference, use that directly, else
255             # make one. also, if no buffer was passed, make an empty one.
256 3 50 66     30 my $valref
    100          
257             = @_ && defined $_[0] ? ( ref( $_[0] ) ? $_[0] : \( $_[0] ) ) : \( q{} );
258              
259 3 50       24 $attrs{len} = length( $$valref ) unless defined $attrs{len};
260              
261             # if called as a class method (ref($obj) not defined)
262             # create an essentially NULL pointer for pass to XPAGet
263 3 50       24 my $xpa = ref( $obj ) ? $obj->{xpa} : nullXPA();
264              
265             _Set( $xpa, $template, $paramlist, _flatten_mode( $attrs{mode} ),
266 3         9 $$valref, $attrs{len}, $attrs{max_servers} );
267             }
268              
269              
270              
271              
272              
273              
274              
275              
276              
277              
278              
279              
280              
281              
282              
283              
284              
285              
286              
287              
288              
289              
290              
291              
292              
293              
294              
295              
296              
297              
298              
299              
300              
301              
302              
303              
304              
305              
306              
307              
308              
309              
310              
311              
312              
313              
314              
315             sub Info {
316 0     0 1 0 my $obj = shift;
317              
318 0 0       0 my $attrs = 'HASH' eq ref $_[-1] ? pop @_ : {};
319              
320 0 0       0 @_ == 2
321             or croak( 'usage: IPC::XPA->Info( $template, $paramlist [,\%attrs]' );
322              
323 0         0 my ( $template, $paramlist ) = @_;
324              
325 0         0 my %attrs = ( %def_attrs, %$attrs );
326              
327             # if called as a class method (ref($obj) not defined)
328             # create an essentially NULL pointer for pass to XPAGet
329 0 0       0 my $xpa = ref( $obj ) ? $obj->{xpa} : nullXPA();
330              
331 0         0 _Info( $xpa, $template, $paramlist, _flatten_mode( $attrs{mode} ), $attrs{max_servers} );
332             }
333              
334              
335              
336              
337              
338              
339              
340              
341              
342              
343              
344              
345              
346              
347              
348              
349              
350              
351              
352              
353              
354              
355              
356              
357              
358              
359              
360              
361              
362              
363              
364              
365             sub Access {
366 7     7 1 1580238 my $obj = shift;
367              
368 7 50       40 my $attrs = 'HASH' eq ref $_[-1] ? pop @_ : {};
369              
370 7 50 33     67 @_ == 1 || @_ == 2
371             or croak( 'usage: IPC::XPA->Access( $template, [,$paramlist] [,\%attrs]' );
372              
373 7         26 my ( $template, $paramlist ) = @_;
374              
375 7         98 my %attrs = ( %def_attrs, %$attrs );
376              
377             # if called as a class method (ref($obj) not defined)
378             # create an essentially NULL pointer for pass to XPAGet
379 7 50       91 my $xpa = ref( $obj ) ? $obj->{xpa} : nullXPA();
380              
381 7         48 _Access( $xpa, $template, $paramlist, _flatten_mode( $attrs{mode} ), $attrs{max_servers} );
382             }
383              
384              
385              
386              
387              
388              
389              
390              
391              
392              
393              
394              
395              
396              
397              
398              
399              
400              
401              
402              
403              
404              
405              
406              
407              
408              
409              
410              
411              
412              
413              
414              
415             sub NSLookup {
416 1     1 1 1629 my $obj = shift;
417              
418 1 50       15 @_ == 2
419             || croak( 'usage: IPC::XPA->NSLookup( $template, $type)' );
420              
421             # if called as a class method (ref($obj) not defined)
422             # create an essentially NULL pointer for pass to XPAGet
423 1 50       18 my $xpa = ref( $obj ) ? $obj->{xpa} : nullXPA();
424              
425 1         671 _NSLookup( $xpa, @_ );
426             }
427              
428             #
429             # This file is part of IPC-XPA
430             #
431             # This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory.
432             #
433             # This is free software, licensed under:
434             #
435             # The GNU General Public License, Version 3, June 2007
436             #
437              
438             1;
439              
440             __END__