line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::SmokeBrew::IniFile; |
2
|
|
|
|
|
|
|
$App::SmokeBrew::IniFile::VERSION = '1.00'; |
3
|
|
|
|
|
|
|
#ABSTRACT: Parse the smokebrew configuration file |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
93714
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
55
|
|
7
|
2
|
|
|
2
|
|
10
|
use base 'Config::INI::Reader'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1002
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub set_value { |
10
|
12
|
|
|
12
|
1
|
2729
|
my ($self, $name, $value) = @_; |
11
|
|
|
|
|
|
|
|
12
|
12
|
50
|
66
|
|
|
43
|
if ( defined $self->{data}{ $self->current_section }{$name} |
|
|
100
|
|
|
|
|
|
13
|
|
|
|
|
|
|
and ref $self->{data}{ $self->current_section }{$name} eq 'ARRAY' ) { |
14
|
0
|
|
|
|
|
0
|
push @{ $self->{data}{ $self->current_section }{$name} }, $value; |
|
0
|
|
|
|
|
0
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
elsif ( defined $self->{data}{ $self->current_section }{$name} ) { |
17
|
|
|
|
|
|
|
$self->{data}{ $self->current_section }{$name} |
18
|
2
|
|
|
|
|
69
|
= [ $self->{data}{ $self->current_section }{$name}, $value ]; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
10
|
|
|
|
|
145
|
$self->{data}{ $self->current_section }{$name} = $value; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
qq[Smokin']; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__END__ |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=pod |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=encoding UTF-8 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
App::SmokeBrew::IniFile - Parse the smokebrew configuration file |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 VERSION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
version 1.00 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use App::SmokeBrew::IniFile; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $cfg = App::SmokeBrew::IniFile->read_file( 'smokebrew.cfg' ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 DESCRIPTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
App::SmokeBrew::IniFile is a subclass of L<Config::INI::Reader> which supports |
50
|
|
|
|
|
|
|
multi-valued parameters. Parameters which are specified multiple times will become |
51
|
|
|
|
|
|
|
an C<arrayref> in the resultant C<hashref> structure that is produced. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 METHODS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This subclass overrides one of the L<Config::INI::Reader> methods: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item C<set_value> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
This method is overriden to support multi-valued parameters. If a parameter is specified multiple |
62
|
|
|
|
|
|
|
times the INI file it will become an C<arrayref>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
If 'foo.ini' contains: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
dir=/home/foo |
67
|
|
|
|
|
|
|
mirror=http://some.mirror.com/ |
68
|
|
|
|
|
|
|
mirror=ftp://some.other.mirror.org/CPAN/ |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $cfg = App::SmokeBrew::IniFile->read_file( 'foo.ini' ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$cfg = { |
73
|
|
|
|
|
|
|
'_' => { |
74
|
|
|
|
|
|
|
dir => '/home/foo', |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
mirrors => [ |
77
|
|
|
|
|
|
|
'http://some.mirror.com/', |
78
|
|
|
|
|
|
|
'ftp://some.other.mirror.org/CPAN/', |
79
|
|
|
|
|
|
|
], |
80
|
|
|
|
|
|
|
}, |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=back |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 KUDOS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Thanks to Ricardo Signes for pointing out his awesome module to me. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SEE ALSO |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L<Config::INI::Reader> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Chris Williams <chris@bingosnet.co.uk> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Chris Williams. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
102
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |