File Coverage

blib/lib/App/SmokeBrew/IniFile.pm
Criterion Covered Total %
statement 13 15 86.6
branch 3 4 75.0
condition 2 3 66.6
subroutine 4 4 100.0
pod 1 1 100.0
total 23 27 85.1


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