File Coverage

blib/lib/ExtUtils/BuildRC.pm
Criterion Covered Total %
statement 41 43 95.3
branch 11 16 68.7
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 64 71 90.1


line stmt bran cond sub pod time code
1             package ExtUtils::BuildRC;
2             {
3             $ExtUtils::BuildRC::VERSION = '0.005';
4             }
5 1     1   22270 use 5.006;
  1         4  
  1         45  
6              
7 1     1   6 use strict;
  1         3  
  1         53  
8 1     1   6 use warnings FATAL => 'all';
  1         2  
  1         58  
9              
10 1     1   5 use Exporter 5.57 qw/import/;
  1         29  
  1         76  
11             our @EXPORT_OK = qw/read_config parse_file/;
12              
13 1     1   6 use Carp qw/croak/;
  1         1  
  1         83  
14 1     1   908 use File::Spec::Functions qw/catfile/;
  1         808  
  1         62  
15 1     1   801 use ExtUtils::Helpers 0.006 qw/split_like_shell/;
  1         7817  
  1         1443  
16              
17             sub _slurp {
18 5     5   11 my $filename = shift;
19 5 50       310 open my $fh, '<', $filename or croak "Couldn't open configuration file '$filename': $!";
20 5         8 my $content = do { local $/ = undef, <$fh> };
  5         183  
21 5 50       60 close $fh or croak "Can't close $filename: $!";
22 5         22 return $content;
23             }
24              
25             sub parse_file {
26 5     5 1 1072 my $filename = shift;
27              
28 5         10 my %ret;
29 5         18 my $content = _slurp($filename);
30              
31 5         22 $content =~ s/ (?
32             LINE:
33 5         77 for my $line (split / \n (?! [ \t\f]) /x, $content) {
34 6 50       194 next LINE if $line =~ / \A \s* \z /xms; # Skip empty lines
35 6 50       87 if (my ($action, $args) = $line =~ m/ \A \s* (\* | [\w.-]+ ) \s+ (.*?) \s* \z /xms) {
36 6         8 push @{ $ret{$action} }, split_like_shell($args);
  6         47  
37             }
38             else {
39 0         0 croak "Can't parse line '$line'";
40             }
41             }
42 5         678 return \%ret;
43             }
44              
45             sub read_config {
46 3 100   3 1 18692 my @files = (
    100          
    100          
47             ($ENV{MODULEBUILDRC} ? $ENV{MODULEBUILDRC} : ()),
48             ($ENV{HOME} ? catfile($ENV{HOME}, '.modulebuildrc') : ()),
49             ($ENV{USERPROFILE} ? catfile($ENV{USERPROFILE}, '.modulebuildrc') : ()),
50             );
51              
52             FILE:
53 3         15 for my $filename (@files) {
54 3 50       87 next FILE if not -e $filename;
55 3         18 return parse_file($filename);
56             }
57 0           return {};
58             }
59              
60             1;
61              
62              
63              
64             =pod
65              
66             =head1 NAME
67              
68             ExtUtils::BuildRC - *DEPRECATED* A reader for Build.PL configuration files
69              
70             =head1 VERSION
71              
72             version 0.005
73              
74             =head1 SYNOPSIS
75              
76             use ExtUtils::BuildRC 'read_config';
77            
78             my $config = read_config();
79             my @build_options = (@{ $config->{build} }, @{ $config->{'*'} });
80              
81             =head1 DESCRIPTION
82              
83             B<.modulebuildrc has been deprecated at the QA Hackathon 2013, this is part of the so called "Lancaster Consensus">.
84              
85             This module parses Build.PL configuration files.
86              
87             =head1 FUNCTIONS
88              
89             =head2 parse_file($filename)
90              
91             Read a Build.PL compatible configuration file. It returns a hash with the actions as keys and arrayrefs of arguments as values.
92              
93             =head2 read_config()
94              
95             Read the first Build.PL configuration file that's available in any of the locations defined by the Build.PL Spec. The data is returned in the same format as C does.
96              
97             =head1 AUTHOR
98              
99             Leon Timmermans
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2010 by Leon Timmermans.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut
109              
110              
111             __END__