line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::MySQL::Reader; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
2582
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
114
|
|
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
124
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
23
|
use base 'Config::INI::Reader'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3030
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Config::MySQL::Reader - Read MySQL-style configuration files |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
If F contains |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
[mysqld] |
25
|
|
|
|
|
|
|
datadir=/var/lib/mysql |
26
|
|
|
|
|
|
|
skip-locking |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
[mysqldump] |
29
|
|
|
|
|
|
|
quick |
30
|
|
|
|
|
|
|
max_allowed_packet = 16M |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
!include /etc/my_other.cnf |
33
|
|
|
|
|
|
|
!include /etc/my_extra.cnf |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Then when your program contains |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $config = Config::MySQL::Reader->read_file('my.cnf'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
C<$config> will contain |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
'_' => { |
43
|
|
|
|
|
|
|
'!include' => [ |
44
|
|
|
|
|
|
|
'/etc/my_other.cnf', |
45
|
|
|
|
|
|
|
'/etc/my_extra.cnf', |
46
|
|
|
|
|
|
|
], |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
'mysqld' => { |
49
|
|
|
|
|
|
|
'datadir' => '/var/lib/mysql', |
50
|
|
|
|
|
|
|
'skip-locking' => undef, |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
'mysqldump' => { |
53
|
|
|
|
|
|
|
'quick' => undef, |
54
|
|
|
|
|
|
|
'max_allowed_packet' => '16M', |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DECSRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This module extends L to support reading |
61
|
|
|
|
|
|
|
MySQL-style configuration files. Although deceptively similar to |
62
|
|
|
|
|
|
|
standard C<.INI> files, they can include bare boolean options with no value |
63
|
|
|
|
|
|
|
assignment and additional features like C and C. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
C does not read files included by the C |
66
|
|
|
|
|
|
|
and C directives, but does preserve the directives so that you can |
67
|
|
|
|
|
|
|
safely read, modify, and re-write configuration files without losing |
68
|
|
|
|
|
|
|
them. If you need to read the contents of included files, you may want to look |
69
|
|
|
|
|
|
|
at L which handles this automatically (but does not |
70
|
|
|
|
|
|
|
handle roundtripping). |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS FOR READING CONFIG |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 read_file, read_string, and read_handle |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
See L for usage details. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 OVERRIDDEN METHODS |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 parse_value_assignment |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Copes with MySQL-style boolean properties that have no value assignment. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub parse_value_assignment { |
87
|
11
|
50
|
|
11
|
1
|
1280
|
return ( $1, $2 ) if $_[1] =~ /^\s*([^=\s][^=]*?)(?:\s*=\s*(.*?)\s*)?$/; |
88
|
0
|
|
|
|
|
0
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 can_ignore |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Handle C and C directives. Comments can start with hash too. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=cut |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub can_ignore { |
98
|
29
|
|
|
29
|
1
|
3374
|
my ( $self, $line ) = @_; |
99
|
29
|
100
|
|
|
|
1064
|
if ( $line =~ /^\s*(\!include(?:dir)?)\s+(.*?)\s*$/ ) { |
100
|
7
|
|
|
|
|
14
|
push @{$self->{data}{$self->starting_section}{$1}}, $2; |
|
7
|
|
|
|
|
45
|
|
101
|
7
|
|
|
|
|
62
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
22
|
100
|
|
|
|
104
|
return $line =~ /\A\s*(?:;|#|$)/ ? 1 : 0; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 preprocess_line |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Strip inline comments (starting with ; or #) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub preprocess_line { |
113
|
15
|
|
|
15
|
1
|
66
|
my ($self, $line) = @_; |
114
|
15
|
|
|
|
|
20
|
${$line} =~ s/\s+[;#].*$//g; |
|
15
|
|
|
|
|
65
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 SEE ALSO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item L |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item L |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Iain Arnell, C<< >> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 BUGS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
136
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
137
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SUPPORT |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
perldoc Config::MySQL::Reader |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
You can also look for information at: |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
L |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
L |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * CPAN Ratings |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * Search CPAN |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
L |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Thanks to Ricardo Signes for Config-INI. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Copyright 2010 Iain Arnell. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
179
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
180
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; # End of Config::MySQL::Reader |