File Coverage

blib/lib/Net/Cisco/ObjectGroup/Base.pm
Criterion Covered Total %
statement 41 45 91.1
branch 10 12 83.3
condition 1 3 33.3
subroutine 8 9 88.8
pod 0 2 0.0
total 60 71 84.5


line stmt bran cond sub pod time code
1             package Net::Cisco::ObjectGroup::Base;
2 6     6   36 use base qw(Class::Data::Inheritable);
  6         9  
  6         5506  
3 6     6   2262 use base qw(Class::Accessor::Fast);
  6         13  
  6         5134  
4              
5 6     6   21494 use strict;
  6         17  
  6         177  
6 6     6   36 use warnings FATAL => qw(all);
  6         13  
  6         280  
7              
8 6     6   6043 use Symbol;
  6         6214  
  6         1639  
9 6     6   36 use Carp;
  6         547  
  6         2686  
10              
11             __PACKAGE__->mk_classdata('__dict');
12              
13             __PACKAGE__->follow_best_practice;
14             __PACKAGE__->mk_accessors(qw( type name desc objs ));
15              
16             sub _init {
17 13     13   22 my $self = shift;
18 13         22 my $arg_ref = shift;
19              
20 13 100       71 return $self unless $arg_ref->{pretty_print};
21 3         7 my $pkg = ref $self;
22              
23 3 50       19 if (!defined $pkg->__dict) {
24 3         37 $pkg->__dict( {} );
25              
26 3         106 my $data = Symbol::qualify_to_ref('DATA', $pkg);
27 3         83 while (my $line = <$data>) {
28 119 100       770 next if $line =~ m/^#/;
29 51 100       129 next if $line !~ m/:/;
30              
31 46         140 $line =~ m/^\s*([0-9]+)\s*:\s*([a-z0-9-]{2,})\s*$/;
32 46 50 33     198 if (defined $1 and defined $2) {
33 46         119 $pkg->__dict->{$1} = $2;
34             }
35             else {
36             # pretty printing is nice but not essential,
37             # so just continue if there is some kind of error.
38 0         0 chomp $line;
39 0         0 carp "syntax error in __DATA__ portion of $pkg: '$line'";
40 0         0 next;
41             }
42             }
43             }
44              
45 3         44 return $self;
46             }
47              
48             sub push {
49 0     0 0 0 croak 'attempt to call push() in base class';
50             }
51              
52             sub dump {
53 17     17 0 1375 my $self = shift;
54 17         213 my $output;
55              
56 17         79 $output .= sprintf "object-group %s %s\n",
57             $self->get_type, $self->get_name;
58              
59 17 100       213 $output .= sprintf " description %s\n",
60             $self->get_desc if defined $self->get_desc;
61              
62 17         158 $output .= join "\n", map {' '. $_} @{$self->get_objs};
  36         144  
  17         49  
63              
64 17         42 chomp $output;
65 17         116 return $output;
66             }
67              
68             1;
69              
70             # Copyright (c) The University of Oxford 2006. All Rights Reserved.
71             #
72             # This program is free software; you can redistribute it and/or modify it
73             # under the terms of version 2 of the GNU General Public License as published
74             # by the Free Software Foundation.
75             #
76             # This program is distributed in the hope that it will be useful, but WITHOUT
77             # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78             # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
79             # more details.
80             #
81             # You should have received a copy of the GNU General Public License along with
82             # this program; if not, write to the Free Software Foundation, Inc., 51
83             # Franklin St, Fifth Floor, Boston, MA 02110-1301 USA