File Coverage

blib/lib/Net/Cisco/ObjectGroup/Service.pm
Criterion Covered Total %
statement 34 35 97.1
branch 23 24 95.8
condition 23 27 85.1
subroutine 6 6 100.0
pod 0 1 0.0
total 86 93 92.4


line stmt bran cond sub pod time code
1             package Net::Cisco::ObjectGroup::Service;
2 2     2   14 use base qw(Net::Cisco::ObjectGroup::Base);
  2         4  
  2         698  
3              
4 2     2   11 use warnings FATAL => qw(all);
  2         4  
  2         120  
5 2     2   10 use strict;
  2         4  
  2         76  
6              
7 2     2   27 use Carp;
  2         5  
  2         1175  
8              
9             sub _init {
10 5     5   9 my $self = shift;
11 5         9 my $arg_ref = shift;
12              
13 5 100       271 croak 'missing parameter "protocol" when creating service group'
14             if !defined $arg_ref->{protocol};
15              
16 4 100       181 croak "unrecognized protocol type: '$arg_ref->{protocol}'"
17             if $arg_ref->{protocol} !~ m/^(?:tcp|udp|tcp-udp)$/;
18              
19 3         20 $self->set_name( $self->get_name ." $arg_ref->{protocol}" );
20 3         83 $self->SUPER::_init( $arg_ref );
21              
22 3         8 return $self;
23             }
24              
25             sub push {
26 8     8 0 9695 my $self = shift;
27 8         13 my $arg_ref = shift;
28              
29 8 100 66     197 croak 'must specify either group-object or service definition'
30             if !defined $arg_ref->{group_object} and !defined $arg_ref->{svc};
31              
32 7 100 100     190 croak 'cannot specify both group-object and service definition'
33             if defined $arg_ref->{group_object} and defined $arg_ref->{svc};
34              
35 6 100 100     178 croak 'missing service operator'
36             if defined $arg_ref->{svc} and !defined $arg_ref->{svc_op};
37              
38 5 100 100     179 croak "unrecognized service operator: '$arg_ref->{svc_op}'"
39             if defined $arg_ref->{svc_op}
40             and $arg_ref->{svc_op} !~ m/^(?:eq|range)$/;
41              
42 4 100 100     186 croak 'bad group-object'
43             if defined $arg_ref->{group_object}
44             and ! UNIVERSAL::isa( $arg_ref->{group_object}, __PACKAGE__ );
45              
46              
47 3 100 66     22 if (defined $arg_ref->{svc}
      100        
48             and defined __PACKAGE__->__dict
49             and exists __PACKAGE__->__dict->{$arg_ref->{svc}}) {
50              
51 1         26 $arg_ref->{svc} = __PACKAGE__->__dict->{$arg_ref->{svc}};
52             }
53              
54 3 50 66     38 if (defined $arg_ref->{svc_hi}
      66        
55             and defined __PACKAGE__->__dict
56             and exists __PACKAGE__->__dict->{$arg_ref->{svc_hi}}) {
57              
58 0         0 $arg_ref->{svc_hi} = __PACKAGE__->__dict->{$arg_ref->{svc_hi}};
59             }
60              
61 3 100       34 my $line = defined $arg_ref->{group_object}
    100          
62             ? 'group-object '. $arg_ref->{group_object}->get_name
63             : defined $arg_ref->{svc_hi}
64             ? "port-object $arg_ref->{svc_op} $arg_ref->{svc} $arg_ref->{svc_hi}"
65             : "port-object $arg_ref->{svc_op} $arg_ref->{svc}";
66              
67 3 100       15 $line =~ s/ \S+$// if defined $arg_ref->{group_object}; # chop off proto
68              
69 3         4 push @{$self->get_objs}, $line;
  3         14  
70              
71 3         33 return $self;
72             }
73              
74             1;
75              
76             # Copyright (c) The University of Oxford 2006. All Rights Reserved.
77             #
78             # This program is free software; you can redistribute it and/or modify it
79             # under the terms of version 2 of the GNU General Public License as published
80             # by the Free Software Foundation.
81             #
82             # This program is distributed in the hope that it will be useful, but WITHOUT
83             # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
84             # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
85             # more details.
86             #
87             # You should have received a copy of the GNU General Public License along with
88             # this program; if not, write to the Free Software Foundation, Inc., 51
89             # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
90              
91             __DATA__