line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Parser::PgOptions; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Test::Parser::PgOptions - Perl module to parse output from pgoption. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Test::Parser::PgOptions; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $parser = new Test::Parser::PgOptions; |
12
|
|
|
|
|
|
|
$parser->parse($text); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This module transforms pgoption 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
|
|
24447
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
26
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
27
|
1
|
|
|
1
|
|
757
|
use Test::Parser; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
30
|
|
28
|
1
|
|
|
1
|
|
1789
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@Test::Parser::PgOptions::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::PgOptions 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::PgOptions $self = fields::new($class); |
51
|
|
|
|
|
|
|
$self->SUPER::new(); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->name('pgoption'); |
54
|
|
|
|
|
|
|
$self->type('standards'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# PgOptions 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 pgoption data. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
sub data { |
70
|
|
|
|
|
|
|
my $self = shift; |
71
|
|
|
|
|
|
|
if (@_) { |
72
|
|
|
|
|
|
|
$self->{data} = @_; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
return {database => {name => 'PostgreSQL', version => $self->{version}, |
75
|
|
|
|
|
|
|
parameters => {parameter => $self->{data}}}}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head3 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Override of Test::Parser's default parse_line() routine to make it able |
81
|
|
|
|
|
|
|
to parse pgoption output. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
sub parse_line { |
85
|
|
|
|
|
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
my $line = shift; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my @i = split /\|/, $line; |
89
|
|
|
|
|
|
|
if (scalar @i == 3 and $i[0] ne 'name') { |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# Trim any leading and trailing whitespaces. |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
$i[0] =~ s/^\s+//; |
94
|
|
|
|
|
|
|
$i[0] =~ s/\s+$//; |
95
|
|
|
|
|
|
|
return 1 if ($i[0] eq 'name'); |
96
|
|
|
|
|
|
|
$i[1] =~ s/^\s+//; |
97
|
|
|
|
|
|
|
$i[1] =~ s/\s+$//; |
98
|
|
|
|
|
|
|
$i[2] =~ s/^\s+//; |
99
|
|
|
|
|
|
|
$i[2] =~ s/\s+$//; |
100
|
|
|
|
|
|
|
push @{$self->{data}}, {name => $i[0], setting => $i[1], |
101
|
|
|
|
|
|
|
description => $i[2]}; |
102
|
|
|
|
|
|
|
$self->{version} = $i[1] if ($i[0] eq 'server_version'); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return 1; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head3 to_xml() |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Returns pgoption data transformed into XML. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
sub to_xml { |
114
|
|
|
|
|
|
|
my $self = shift; |
115
|
|
|
|
|
|
|
my $outfile = shift; |
116
|
|
|
|
|
|
|
return XMLout({name => 'PostgreSQL', version => $self->{version}, |
117
|
|
|
|
|
|
|
parameters => {parameter => $self->{data}}}, |
118
|
|
|
|
|
|
|
RootName => 'database'); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
__END__ |