| 1 | package ExtUtils::BuildRC; | ||||||||||||||||||
| 2 | { | ||||||||||||||||||
| 3 | 2 | $ExtUtils::BuildRC::VERSION = '0.005'; | |||||||||||||||||
| 4 | } | ||||||||||||||||||
| 5 | 2 | ▶ | use 5.006; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 2 | ▶ | use Exporter 5.57 qw/import/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 2 | our @EXPORT_OK = qw/read_config parse_file/; | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 14 | 2 | ▶ | use File::Spec::Functions qw/catfile/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 15 | 2 | ▶ | use ExtUtils::Helpers 0.006 qw/split_like_shell/; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | 5 | ▶ | sub _slurp { | ||||||||||||||||
|
Subroutine
_slurp: called CC=3 SCAR=11.2
| |||||||||||||||||||
| 18 | 5 | my $filename = shift; | |||||||||||||||||
| 19 | 5 | ▶ | open my $fh, '<', $filename or croak "Couldn't open configuration file '$filename': $!"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 20 | 5 | my $content = do { local $/ = undef, <$fh> }; | |||||||||||||||||
| 21 | 5 | ▶ | close $fh or croak "Can't close $filename: $!"; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 22 | 5 | return $content; | |||||||||||||||||
| 23 | } | ||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 5 | ▶ | sub parse_file { | ||||||||||||||||
|
Subroutine
parse_file: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||
| 26 | 5 | my $filename = shift; | |||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 5 | my %ret; | |||||||||||||||||
| 29 | 5 | my $content = _slurp($filename); | |||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 5 | $content =~ s/ (?<!\\) \# [^\n]*//gxm; # Remove comments | |||||||||||||||||
| 32 | LINE: | ||||||||||||||||||
| 33 | 5 | for my $line (split / \n (?! [ \t\f]) /x, $content) { | |||||||||||||||||
| 34 | 6 | ▶ | next LINE if $line =~ / \A \s* \z /xms; # Skip empty lines | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 35 | 6 | ▶ | if (my ($action, $args) = $line =~ m/ \A \s* (\* | [\w.-]+ ) \s+ (.*?) \s* \z /xms) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | 6 | push @{ $ret{$action} }, split_like_shell($args); | |||||||||||||||||
| 37 | } | ||||||||||||||||||
| 38 | else { | ||||||||||||||||||
| 39 | 0 | croak "Can't parse line '$line'"; | |||||||||||||||||
| 40 | } | ||||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | 5 | return \%ret; | |||||||||||||||||
| 43 | } | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 3 | ▶ | sub read_config { | ||||||||||||||||
|
Subroutine
read_config: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||
| 46 | my @files = ( | ||||||||||||||||||
| 47 | ($ENV{MODULEBUILDRC} ? $ENV{MODULEBUILDRC} : ()), | ||||||||||||||||||
| 48 | ($ENV{HOME} ? catfile($ENV{HOME}, '.modulebuildrc') : ()), | ||||||||||||||||||
| 49 | 3 | ▶ | ($ENV{USERPROFILE} ? catfile($ENV{USERPROFILE}, '.modulebuildrc') : ()), | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 50 | ); | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | FILE: | ||||||||||||||||||
| 53 | 3 | for my $filename (@files) { | |||||||||||||||||
| 54 | 3 | ▶ | next FILE if not -e $filename; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 55 | 3 | return parse_file($filename); | |||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | 0 | return {}; | |||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | 2 | 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<parse_file> does. | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | =head1 AUTHOR | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | Leon Timmermans <fawaka@gmail.com> | ||||||||||||||||||
| 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__ | ||||||||||||||||||