Object.pm

filter: Statementstmt 22.4% 11 / 49 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 25.0% 3 / 12 Podpod 83.3% 5 / 6 totaltotal 19.7% 19 / 96 CC 10 SCAR 27.4
CC
10
Cov
15%
new
42.0
_init
12.0
first
6.0
CRAP 15.5
« Object/network.pm ↑ Summary Object/protocol.pm »
1 package PIX::Object;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '1.10';
9  
10 =pod
11  
12 =head1 NAME
13  
14 PIX::Object - Factory class for the various object-groups found in a PIX config
15 from a PIX::Walker object. This object is not meant to be instantiated directly.
16  
17 =head1 SYNOPSIS
18  
19 PIX::Walker uses this factory class to create perl objects for each object-group
20 found within a firewall configuration. Programs will interface with this object
21 but will practically never instantiate objects from this factory directly.
22  
23 =head1 SEE ALSO
24  
25 B<PIX::Object::network>, B<PIX::Object::service>, B<PIX::Object::protocol>
26  
27 =head1 EXAMPLE
28  
29 my $obj = new PIX::Object($type, $name, $conf_block, $pix_walker_ref);
30  
31 =head1 METHODS
32  
33 =over
34  
35 =cut
36  
37 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
38 0 my $proto = shift;
39 0 ▶ my $class = ref($proto) || $proto;
Condition0%0/3
ref $proto || $proto
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
40 0 my $self = { };
41 0 my ($type, $name, $config, $walker) = @_;
42 0 ▶ croak("Must provide the object-group type, name and config block") unless ($type and $name and $config);
Branch: 1 branch
BranchTrueFalseTotal
unless $type and $name and $config 0 0 0
Condition0%0/6
$type and $name and $config
!ll&&!rl&&r
000
$type and $name
!ll&&!rl&&r
000
MC/DC0%0/3
$type and $name and $config
$type $name $config
Truth table0%0/4
A and B and C
A= $typeB= $nameC= $config
ABCresult
0XX0
10X0
1100
1111
43  
44 0 $class .= "::" . lc $type;
45 0 $class =~ tr/-/_/;
46 0 eval "require $class";
47 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
48 0 die("Object subclass '$class' has compile time errors:\n$@\n");
49 }
50  
51 0 $self->{class} = $class;
52 0 $self->{name} = $name;
53 0 $self->{type} = $type;
54 0 $self->{config} = [ @$config ];
55 0 $self->{config_block} = [ @$config ];
56 0 $self->{walker} = $walker;
57  
58 0 bless($self, $class);
59 0 $self->_init;
60  
61 0 return $self;
62 }
63  
64 =item B<type( )>
65  
66 =over
67  
68 Returns the type of the object group. One of "network", "service", "protocol",
69 or "icmp_type"
70  
71 =back
72  
73 =cut
74 0 ▶sub type { $_[0]->{type} }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
75  
76 =item B<name( )>
77  
78 =over
79  
80 Returns the name of the object group as configured.
81  
82 =back
83  
84 =cut
85 0 ▶sub name { $_[0]->{name} }
Subroutine name: not called CC=1 SCAR=6.9
Pod documented
86  
87 =item B<list( )>
88  
89 =over
90  
91 Returns a list of items from the object group. The structure of the list
92 returned will vary depending on the object-group type. See each sub-class for
93 more information.
94  
95 B<PIX::Object::network>, B<PIX::Object::service>, B<PIX::Object::protocol>
96  
97 =back
98  
99 =cut
100 0 ▶sub list { undef }
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
101  
102 =item B<first( )>
103  
104 =over
105  
106 Returns the first object from the object-group list.
107  
108 =back
109  
110 =cut
111 0 ▶sub first {
Subroutine first: not called CC=2 SCAR=17.9
Pod documented
112 0 my ($self) = @_;
113 0 my @list = $self->list;
114 0 ▶ return @list ? $list[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@list ? : 0 0 0
115 }
116  
117 =item B<alias($alias)>
118  
119 =over
120  
121 Returns the IP of the alias given in $alias. If no alias is found than the
122 string is returned unchanged. This simply deligates to the alias sub from the
123 PIX::Walker object as given in new().
124  
125 =back
126  
127 =cut
128 0 ▶sub alias {
Subroutine alias: not called CC=2 SCAR=17.9
Pod documented
129 0 my $self = shift;
130 0 my $alias = shift;
131 0 ▶ return defined $self->{walker} ? $self->{walker}->alias($alias) : $alias;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'walker'} ? : 0 0 0
132 }
133  
134 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
135 0 my $self = shift;
136  
137 # It's possible for the config block to be an empty list, in which case
138 # we don't count that as being invalid.
139 0 ▶ if (@{$self->{config_block}} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"config_block"};} and not @{$$self{"config_block"};}[0] =~ /^object-group \S+ \S+/i) 0 0 0
Condition0%0/3
@{$self->{"config_block"};} and not @{$$self{"config_block"};}[0] =~ /^object-group \S+ \S+/i
!ll&&!rl&&r
000
MC/DC0%0/2
@{$self->{"config_block"};} and not @{$$self{"config_block"};}[0] =~ /^object-group \S+ \S+/i
@{$self->{"config_block"};} not @{$$self{"config_block"};}[0] =~ /^object-group \S+ \S+/i
Truth table0%0/3
A and not(B)
A= @{$self->{"config_block"};}B= not @{$$self{"config_block"};}[0] =~ /^object-group \S+ \S+/i
ABresult
0X0
100
111
140 0 @{$self->{config_block}}[0] !~ /^object-group \S+ \S+/i) {
141 0 carp("Invalid config block passed to $self->{class}");
142 0 return undef;
143 }
144 }
145  
146 0 ▶sub _nextline { shift @{$_[0]->{config_block}} }
Subroutine _nextline: not called CC=1 SCAR=6.9
147 0 ▶sub _rewind { unshift @{$_[0]->{config_block}}, $_[1] }
Subroutine _rewind: not called CC=1 SCAR=6.9
148  
149 1 1;
150  
151 =pod
152  
153 =head1 AUTHOR
154  
155 Jason Morriss <lifo 101 at - gmail dot com>
156  
157 =head1 BUGS
158  
159 Please report any bugs or feature requests to
160 C<bug-pix-walker at rt.cpan.org>, or through the web interface at
161 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PIX-Walker>.
162 I will be notified, and then you'll automatically be notified of progress on
163 your bug as I make changes.
164  
165 =head1 SUPPORT
166  
167 perldoc PIX::Walker
168  
169 perldoc PIX::Accesslist
170 perldoc PIX::Accesslist::Line
171  
172 perldoc PIX::Object
173 perldoc PIX::Object::network
174 perldoc PIX::Object::service
175 perldoc PIX::Object::protocol
176 perldoc PIX::Object::icmp_type
177  
178 =head1 COPYRIGHT & LICENSE
179  
180 Copyright 2006-2008 Jason Morriss, all rights reserved.
181  
182 This program is free software; you can redistribute it and/or modify it
183 under the same terms as Perl itself.
184  
185 =cut
« Object/network.pm ↑ Summary Object/protocol.pm »