blib/lib/SNMP/Effective/VarList.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 70 CC 9 SCAR 40.0
CC
9
Cov
0%
PUSH
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 54.8
1 package SNMP::Effective::VarList;
2  
3 =head1 NAME
4  
5 SNMP::Effective::VarList - Helper module for SNMP::Effective::Host
6  
7 =head1 DESCRIPTION
8  
9 Thist module allows oid/oid-methods to be specified in different ways.
10  
11 =head1 SYNOPSIS
12  
13 use SNMP::Effective::VarList;
14 tie @varlist, 'SNMP::Effective::VarList';
15  
16 push @varlist, [$method1, $oid1], [$method2, $oid2];
17 push @varlist, [$method1, $Varbind_obj1], [$method2, $Varbind_obj2];
18 push @varlist, [$method1, $VarList_obj1], [$method2, $VarList_obj2];
19  
20 =cut
21  
22 use warnings;
23 use strict;
24 use SNMP;
25 use Tie::Array;
26 use Carp qw/ confess /;
27  
28 use base qw/ Tie::StdArray /;
29  
30 sub PUSH {
31 my $self = shift;
32 my @args = @_;
33  
34 LIST:
35 for my $list (@args) {
36 unless(ref $list eq 'ARRAY') {
37 confess "A list of array-refs are required to push()";
38 }
39 unless(@$list > 1) {
40 confess "Each array-ref to push() must have more than one element";
41 }
42 unless($SNMP::Effective::Dispatch::METHOD{$list->[0]}) {
43 confess "The first element in the array-ref to push() must exist in \%SNMP::Effective::Dispatch::METHOD";
44 }
45  
46 my $method = $list->[0];
47 my $i = 0;
48 my @varlist;
49  
50 OID:
51 for my $oid (@$list) {
52 next unless($i++); # skip the first element, containing the method
53  
54 if(ref $oid eq '') { # create varbind
55 $oid = SNMP::Varbind->new([ $oid ]);
56 }
57 if(ref $oid eq 'SNMP::Varbind') { # append varbind
58 push @varlist, $oid;
59 next OID;
60 }
61 if(ref $oid eq 'SNMP::VarList') { # append varlist
62 push @varlist, @$oid;
63 next OID;
64 }
65 }
66  
67 if(@varlist) {
68 push @$self, [ $method, SNMP::VarList->new(@varlist) ];
69 }
70 }
71  
72 return $self->FETCHSIZE;
73 }
74  
75 =head1 AUTHOR
76  
77 =head1 ACKNOWLEDGEMENTS
78  
79 =head1 COPYRIGHT & LICENSE
80  
81 See L<SNMP::Effective>
82  
83 =cut
84  
85 1;