blib/lib/Alien/Build/Plugin/PkgConfig/MakeStatic.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 68.1% 15 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 90.4% 76 / 84 CC 14 SCAR 14.8
CC
14
Cov
89%
_convert
8.1
_recurse
4.0
__ANON__
3.0
CRAP 4.4
« blib/lib/Alien/Build/Plugin/Fetch/Local.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/SHA.pm »
1 package Alien::Build::Plugin::PkgConfig::MakeStatic;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Convert .pc files into static
10 2 our $VERSION = '2.88'; # VERSION
11  
12  
13 2 has path => undef;
14  
15 sub _convert
16 2 ▶{
Subroutine _convert: called CC=8 SCAR=21.0
17 2 my($self, $build, $path) = @_;
18  
19 2 ▶ die "unable to read $path" unless -r $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $path 0 2 2
20 2 ▶ die "unable to write $path" unless -w $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -w $path 0 2 2
21  
22 2 $build->log("converting $path to static");
23  
24 my %h = map {
25 2 my($key, $value) = /^(.*?):(.*?)$/;
26 6 $value =~ s{^\s+}{};
27 6 $value =~ s{\s+$}{};
28 6 ($key => $value);
29 } grep /^(?:Libs|Cflags)(?:\.private)?:/, $path->lines;
30  
31 2 ▶ $h{Cflags} = '' unless defined $h{Cflags};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h{"Cflags"} 1 1 2
32 2 ▶ $h{Libs} = '' unless defined $h{Libs};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h{"Libs"} 0 2 2
33  
34 2 ▶ $h{Cflags} .= ' ' . $h{"Cflags.private"} if defined $h{"Cflags.private"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h{"Cflags.private"} 1 1 2
35 2 ▶ $h{Libs} .= ' ' . $h{"Libs.private"} if defined $h{"Libs.private"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $h{"Libs.private"} 2 0 2
36  
37 2 $h{"Cflags.private"} = '';
38 2 $h{"Libs.private"} = '';
39  
40 8 ▶ $path->edit_lines(sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
41  
42 8 ▶ if(/^(.*?):/)
Branch: 1 branch
BranchTrueFalseTotal
if (/^(.*?):/) 6 2 8
43 {
44 6 my $key = $1;
45 6 ▶ if(defined $h{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{$key}) 6 0 6
46 {
47 6 s/^(.*?):.*$/$1: $h{$key} /;
48 6 delete $h{$key};
49 }
50 }
51  
52 2 });
53  
54 2 $path->append("$_: $h{$_}\n") foreach keys %h;
55 }
56  
57 sub _recurse
58 3 ▶{
Subroutine _recurse: called CC=4 SCAR=13.9
59 3 my($self, $build, $dir) = @_;
60  
61 3 foreach my $child ($dir->children)
62 {
63 4 ▶ if(-d $child)
Branch: 2 branches
BranchTrueFalseTotal
if (-d $child) { } 2 2 4
elsif ($child->basename =~ /\.pc$/) { } 2 0 2
64 {
65 2 $self->_recurse($build, $child);
66 }
67 elsif($child->basename =~ /\.pc$/)
68 {
69 2 $self->_convert($build, $child);
70 }
71 }
72 }
73  
74 sub init
75 1 ▶{
Subroutine init: called CC=1 SCAR=0.1
Pod documented
76 1 my($self, $meta) = @_;
77  
78 1 $meta->add_requires('configure' => 'Alien::Build::Plugin::Build::SearchDep' => '0.35');
79  
80 $meta->before_hook(
81 1 ▶ gather_share => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
82 1 my($build) = @_;
83  
84 1 ▶ if($self->path)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->path) { } 0 1 1
85 {
86 0 $self->_convert($build, Path::Tiny->new($self->path)->absolute);
87 }
88 else
89 {
90 1 $self->_recurse($build, Path::Tiny->new(".")->absolute);
91 }
92  
93 },
94 1 );
95 }
96  
97 2 1;
98  
99 __END__
« blib/lib/Alien/Build/Plugin/Fetch/Local.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/SHA.pm »