| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Parser::Sysctl; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Parser::Sysctl - Perl module to parse output from sysctl. |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Parser::Sysctl; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $parser = new Test::Parser::Sysctl; |
|
12
|
|
|
|
|
|
|
$parser->parse($text); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module transforms sysctl output into a hash that can be used to |
|
17
|
|
|
|
|
|
|
generate XML. |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Also see L for functions available from the base class. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
31684
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
39
|
|
|
26
|
1
|
|
|
1
|
|
1430
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
37
|
|
|
27
|
1
|
|
|
1
|
|
618
|
use Test::Parser; |
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
27
|
|
|
28
|
1
|
|
|
1
|
|
1965
|
use XML::Simple; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@Test::Parser::Sysctl::ISA = qw(Test::Parser); |
|
31
|
|
|
|
|
|
|
use base 'Test::Parser'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use fields qw( |
|
34
|
|
|
|
|
|
|
data |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use vars qw( %FIELDS $AUTOLOAD $VERSION ); |
|
38
|
|
|
|
|
|
|
our $VERSION = '1.7'; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new() |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Creates a new Test::Parser::Sysctl instance. |
|
43
|
|
|
|
|
|
|
Also calls the Test::Parser base class' new() routine. |
|
44
|
|
|
|
|
|
|
Takes no arguments. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
|
49
|
|
|
|
|
|
|
my $class = shift; |
|
50
|
|
|
|
|
|
|
my Test::Parser::Sysctl $self = fields::new($class); |
|
51
|
|
|
|
|
|
|
$self->SUPER::new(); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->name('sysctl'); |
|
54
|
|
|
|
|
|
|
$self->type('standards'); |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# |
|
57
|
|
|
|
|
|
|
# Sysctl data in an array. |
|
58
|
|
|
|
|
|
|
# |
|
59
|
|
|
|
|
|
|
$self->{data} = []; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return $self; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head3 data() |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Returns a hash representation of the sysctl data. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
|
69
|
|
|
|
|
|
|
sub data { |
|
70
|
|
|
|
|
|
|
my $self = shift; |
|
71
|
|
|
|
|
|
|
if (@_) { |
|
72
|
|
|
|
|
|
|
$self->{data} = @_; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
return {parameters => {parameter => $self->{data}}}; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head3 |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Override of Test::Parser's default parse_line() routine to make it able |
|
80
|
|
|
|
|
|
|
to parse sysctl output. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
|
83
|
|
|
|
|
|
|
sub parse_line { |
|
84
|
|
|
|
|
|
|
my $self = shift; |
|
85
|
|
|
|
|
|
|
my $line = shift; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my @i = split /\=/, $line; |
|
88
|
|
|
|
|
|
|
# |
|
89
|
|
|
|
|
|
|
# Trim any leading and trailing whitespaces. |
|
90
|
|
|
|
|
|
|
# |
|
91
|
|
|
|
|
|
|
$i[0] =~ s/^\s+//; |
|
92
|
|
|
|
|
|
|
$i[0] =~ s/\s+$//; |
|
93
|
|
|
|
|
|
|
$i[1] =~ s/^\s+//; |
|
94
|
|
|
|
|
|
|
$i[1] =~ s/\s+$//; |
|
95
|
|
|
|
|
|
|
push @{$self->{data}}, {variable => $i[0], value => $i[1]}; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return 1; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head3 to_xml() |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns sysctl data transformed into XML. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
|
105
|
|
|
|
|
|
|
sub to_xml { |
|
106
|
|
|
|
|
|
|
my $self = shift; |
|
107
|
|
|
|
|
|
|
my $outfile = shift; |
|
108
|
|
|
|
|
|
|
return XMLout({parameter => $self->{data}}, RootName => 'parameters'); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
|
112
|
|
|
|
|
|
|
__END__ |