File Coverage

blib/lib/Config/MVP/Reader/INI.pm
Criterion Covered Total %
statement 34 36 94.4
branch 6 8 75.0
condition 2 3 66.6
subroutine 10 11 90.9
pod 1 2 50.0
total 53 60 88.3


line stmt bran cond sub pod time code
1             package Config::MVP::Reader::INI 2.101464;
2             # ABSTRACT: an MVP config reader for .ini files
3              
4 1     1   86456 use Moose;
  1         400067  
  1         5  
5             extends 'Config::MVP::Reader';
6             with 'Config::MVP::Reader::Findable::ByExtension';
7              
8 1     1   6988 use Config::MVP 2; # Reader is a base class
  1         128  
  1         87  
9              
10             #pod =head1 DESCRIPTION
11             #pod
12             #pod Config::MVP::Reader::INI reads F<.ini> files containing MVP-style
13             #pod configuration.
14             #pod
15             #pod =cut
16              
17             # Clearly this should be an attribute with a builder blah blah blah. -- rjbs,
18             # 2009-07-25
19 0     0 0 0 sub default_extension { 'ini' }
20              
21             sub read_into_assembler {
22 1     1 1 2780 my ($self, $location, $assembler) = @_;
23              
24 1         14 my $reader = Config::MVP::Reader::INI::INIReader->new($assembler);
25 1         7 $reader->read_file($location);
26              
27 1         659 return $assembler->sequence;
28             }
29              
30             {
31             package
32             Config::MVP::Reader::INI::INIReader;
33 1     1   6 use parent 'Config::INI::Reader';
  1         2  
  1         5  
34              
35             sub new {
36 1     1   4 my ($class, $assembler) = @_;
37 1         10 my $self = $class->SUPER::new;
38 1         12 $self->{assembler} = $assembler;
39 1         2 return $self;
40             }
41              
42 25     25   103 sub assembler { $_[0]{assembler} }
43              
44             sub change_section {
45 4     4   1408 my ($self, $section) = @_;
46              
47 4         23 my ($package, $name) = $section =~ m{\A\s*(?:([^/\s]+)\s*/\s*)?(.+)\z};
48 4 100 66     22 $package = $name unless defined $package and length $package;
49              
50 4 50       11 Carp::croak qq{couldn't understand section header: "$_[1]"}
51             unless $package;
52              
53 4         9 $self->assembler->change_section($package, $name);
54             }
55              
56             sub finalize {
57 1     1   289 my ($self) = @_;
58 1         3 $self->assembler->finalize;
59             }
60              
61             sub set_value {
62 9     9   15002 my ($self, $name, $value) = @_;
63 9 100       22 unless ($self->assembler->current_section) {
64 1         116 my $starting_name = $self->starting_section;
65              
66 1 50       34 if ($self->assembler->sequence->section_named( $starting_name )) {
67 0         0 Carp::croak q{can't set value outside of section once starting }
68             . q{section exists};
69             }
70              
71 1         52 $self->assembler->change_section(\undef, $starting_name);
72             }
73              
74 9         3489 $self->assembler->add_value($name, $value);
75             }
76             }
77              
78 1     1   31727 no Moose;
  1         2  
  1         6  
79             __PACKAGE__->meta->make_immutable;
80             1;
81              
82             __END__
83              
84             =pod
85              
86             =encoding UTF-8
87              
88             =head1 NAME
89              
90             Config::MVP::Reader::INI - an MVP config reader for .ini files
91              
92             =head1 VERSION
93              
94             version 2.101464
95              
96             =head1 DESCRIPTION
97              
98             Config::MVP::Reader::INI reads F<.ini> files containing MVP-style
99             configuration.
100              
101             =head1 PERL VERSION
102              
103             This module should work on any version of perl still receiving updates from
104             the Perl 5 Porters. This means it should work on any version of perl released
105             in the last two to three years. (That is, if the most recently released
106             version is v5.40, then this module should work on both v5.40 and v5.38.)
107              
108             Although it may work on older versions of perl, no guarantee is made that the
109             minimum required version will not be increased. The version may be increased
110             for any reason, and there is no promise that patches will be accepted to lower
111             the minimum required perl.
112              
113             =head1 AUTHOR
114              
115             Ricardo Signes <rjbs@semiotic.systems>
116              
117             =head1 CONTRIBUTORS
118              
119             =for stopwords nperez Olivier Mengué
120              
121             =over 4
122              
123             =item *
124              
125             nperez <nperez@cpan.org>
126              
127             =item *
128              
129             Olivier Mengué <dolmen@cpan.org>
130              
131             =back
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is copyright (c) 2008 by Ricardo Signes.
136              
137             This is free software; you can redistribute it and/or modify it under
138             the same terms as the Perl 5 programming language system itself.
139              
140             =cut