File Coverage

blib/lib/Dist/Zilla/Util/ExpandINI/Reader.pm
Criterion Covered Total %
statement 43 44 97.7
branch 8 10 80.0
condition 2 3 66.6
subroutine 10 10 100.0
pod 5 5 100.0
total 68 72 94.4


line stmt bran cond sub pod time code
1 10     10   750 use 5.006;
  10         22  
2 10     10   43 use strict;
  10         14  
  10         254  
3 10     10   35 use warnings;
  10         16  
  10         614  
4              
5             package Dist::Zilla::Util::ExpandINI::Reader;
6              
7             our $VERSION = '0.003003';
8              
9             # ABSTRACT: An order-preserving INI reader
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 10     10   41 use Carp qw(croak);
  10         9  
  10         687  
14              
15 10     10   1398 use parent 'Config::INI::Reader';
  10         877  
  10         100  
16              
17             sub new {
18 9     9 1 7432 my ($class) = @_;
19              
20 9         95 my $self = {
21             data => [],
22             sections => {},
23             };
24              
25 9         94 bless $self => $class;
26 9         44 $self->{current_section} = { name => $self->starting_section, lines => [], comment_lines => [] };
27              
28 9         79 return $self;
29             }
30              
31             sub can_ignore {
32 120     120 1 5637 my ( $self, $line, ) = @_;
33 120 100       266 if ( $line =~ /\A\s*;(.*?)\s*$/msx ) {
34 14         10 push @{ $self->{current_section}->{comment_lines} }, "$1";
  14         32  
35 14         21 return 1;
36             }
37 106 100       303 return $line =~ /\A\s*$/msx ? 1 : 0;
38             }
39              
40             sub change_section {
41 26     26 1 224 my ( $self, $section ) = @_;
42              
43 26         130 my ( $package, $name ) = $section =~ m{
44             \A \s* # Ignore leading whitespace
45             (?: # Optional Non Capture Group
46             ([^/\s]+) # Capture a bunch chars at the front
47             \s* # then skip over subsequent whitespace
48             / # and slash divider
49             \s*
50             )?
51             (.+) # Capture the rest as a complete token
52             \z
53             }msx;
54 26 100 66     144 $package = $name unless defined $package and length $package;
55              
56 26 50       42 Carp::croak qq{couldn't understand section header: "$section"}
57             unless $package;
58              
59 26         20 push @{ $self->{data} }, $self->{current_section};
  26         50  
60              
61 26 50       58 if ( exists $self->{sections}->{$name} ) {
62 0         0 Carp::croak qq{Duplicate section $name ( $package )};
63             }
64 26         51 $self->{sections}->{$name} = 1;
65             $self->{current_section} = {
66 26         82 name => $name,
67             package => $package,
68             lines => [],
69             comment_lines => [],
70             };
71 26         52 return;
72             }
73              
74             sub set_value {
75 54     54 1 696 my ( $self, $name, $value ) = @_;
76              
77 54         41 push @{ $self->{current_section}->{lines} }, $name, $value;
  54         121  
78 54         71 return;
79             }
80              
81             sub finalize {
82 9     9 1 286 my ($self) = @_;
83 9         12 push @{ $self->{data} }, $self->{current_section};
  9         16  
84 9         18 return;
85             }
86              
87             1;
88              
89             __END__
90              
91             =pod
92              
93             =encoding UTF-8
94              
95             =head1 NAME
96              
97             Dist::Zilla::Util::ExpandINI::Reader - An order-preserving INI reader
98              
99             =head1 VERSION
100              
101             version 0.003003
102              
103             =head1 AUTHOR
104              
105             Kent Fredric <kentnl@cpan.org>
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
110              
111             This is free software; you can redistribute it and/or modify it under
112             the same terms as the Perl 5 programming language system itself.
113              
114             =cut