blib/lib/ExtUtils/Packlist.pm

filter: Statementstmt 79.5% 97 / 122 Branchbran 65.0% 26 / 40 Conditioncond 50.0% 12 / 24 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 90.4% 19 / 21 Podpod 100% 6 / 6 totaltotal 70.7% 162 / 229 CC 32 SCAR 23.7
CC
32
Cov
73%
write
25.5
__find_relocations
20.0
read
9.7
CRAP 10.7
« blib/lib/ExtUtils/Installed.pm ↑ Summary Makefile.PL »
1 package ExtUtils::Packlist;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 4 ▶use Carp qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 our $Relocations;
7 4 our $VERSION = '2.18';
8 4 $VERSION = eval $VERSION;
9  
10 # Used for generating filehandle globs. IO::File might not be available!
11 4 my $fhname = "FH1";
12  
13 =begin _undocumented
14  
15 =over
16  
17 =item mkfh()
18  
19 Make a filehandle. Same kind of idea as Symbol::gensym().
20  
21 =cut
22  
23 sub mkfh()
24 {
25 4 ▶no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1024 ▶local $^W;
Subroutine mkfh: called CC=1 SCAR=0.0
Pod documented
27 1024 my $fh = \*{$fhname++};
28 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1024 return($fh);
30 }
31  
32 =item __find_relocations
33  
34 Works out what absolute paths in the configuration have been located at run
35 time relative to $^X, and generates a regexp that matches them
36  
37 =back
38  
39 =end _undocumented
40  
41 =cut
42  
43 sub __find_relocations
44 {
45 0 ▶ my %paths;
Subroutine __find_relocations: not called CC=4 SCAR=30.0
46 0 ▶ while (my ($raw_key, $raw_val) = each %Config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %ExtUtils::Packlist::Config) 0 0 0
47 0 my $exp_key = $raw_key . "exp";
48 0 ▶ next unless exists $Config{$exp_key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ExtUtils::Packlist::Config{$exp_key} 0 0 0
49 0 ▶ next unless $raw_val =~ m!\.\.\./!;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw_val =~ m[\.\.\./] 0 0 0
50 0 $paths{$Config{$exp_key}}++;
51 }
52 # Longest prefixes go first in the alternatives
53 0 my $alternations = join "|", map {quotemeta $_}
54 0 sort {length $b <=> length $a} keys %paths;
55 0 qr/^($alternations)/o;
56 }
57  
58 sub new($$)
59 {
60 1016 ▶my ($class, $packfile) = @_;
Subroutine new: called CC=2 SCAR=7.2
Pod documented
61 1016 ▶$class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010160
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
62 1016 my %self;
63 1016 tie(%self, $class, $packfile);
64 1016 return(bless(\%self, $class));
65 }
66  
67 sub TIEHASH
68 {
69 1017 ▶my ($class, $packfile) = @_;
Subroutine TIEHASH: called CC=3 SCAR=11.0
70 1017 my $self = { packfile => $packfile };
71 1017 bless($self, $class);
72 1017 ▶$self->read($packfile) if (defined($packfile) && -f $packfile);
Branch: 1 branch
BranchTrueFalseTotal
if defined $packfile and -f $packfile 988 29 1017
Condition100%3/3
defined $packfile and -f $packfile
!ll&&!rl&&r
209988
MC/DC100%2/2
defined $packfile and -f $packfile
defined $packfile -f $packfile
Truth table100%3/3
A and B
A= defined $packfileB= -f $packfile
ABresult
0X0
100
111
73 1017 return($self);
74 }
75  
76 sub STORE
77 {
78 18 ▶$_[0]->{data}->{$_[1]} = $_[2];
Subroutine STORE: called CC=1 SCAR=0.0
79 }
80  
81 sub FETCH
82 {
83 18 ▶return($_[0]->{data}->{$_[1]});
Subroutine FETCH: called CC=1 SCAR=0.0
84 }
85  
86 sub FIRSTKEY
87 {
88 1 ▶my $reset = scalar(keys(%{$_[0]->{data}}));
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
89 1 return(each(%{$_[0]->{data}}));
90 }
91  
92 sub NEXTKEY
93 {
94 1 ▶return(each(%{$_[0]->{data}}));
Subroutine NEXTKEY: called CC=1 SCAR=0.0
95 }
96  
97 sub EXISTS
98 {
99 990 ▶return(exists($_[0]->{data}->{$_[1]}));
Subroutine EXISTS: called CC=1 SCAR=0.0
100 }
101  
102 sub DELETE
103 {
104 1 ▶return(delete($_[0]->{data}->{$_[1]}));
Subroutine DELETE: called CC=1 SCAR=0.0
105 }
106  
107 sub CLEAR
108 {
109 1 ▶%{$_[0]->{data}} = ();
Subroutine CLEAR: called CC=1 SCAR=0.0
110 }
111  
112 sub DESTROY
113 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
114 }
115  
116 sub read($;$)
117 {
118 1005 ▶my ($self, $packfile) = @_;
Subroutine read: called CC=9 SCAR=22.7
Pod documented
119 1005 ▶$self = tied(%$self) || $self;
Condition66%2/3
tied %$self || $self
l!l&&r!l&&!r
149910
MC/DC0%0/2
tied %$self || $self
tied %$self $self
Truth table66%2/3
A || B
A= tied %$selfB= $self
ABresult
1X1
011
000
120  
121 1005 ▶if (defined($packfile)) { $self->{packfile} = $packfile; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packfile) { } 1004 1 1005
122 1 else { $packfile = $self->{packfile}; }
123 1005 ▶Carp::croak("No packlist filename specified") if (! defined($packfile));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packfile 1 1004 1005
124 1004 my $fh = mkfh();
125 1004 ▶open($fh, "<$packfile") || Carp::croak("Can't open file $packfile: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$packfile" or Carp::croak("Can't open file ${packfile}: $!") 1 1003 1004
126 1003 $self->{data} = {};
127 1003 my ($line);
128 1003 ▶while (defined($line = <$fh>))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 57285 1003 58288
129 {
130 57285 chomp $line;
131 57285 my ($key, $data) = $line;
132 57285 ▶ if ($key =~ /^(.*?)( \w+=.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^(.*?)( \w+=.*)$/) 1911 55374 57285
133 {
134 1911 $key = $1;
135 1911 $data = { map { split('=', $_) } split(' ', $2)};
136  
137 1911 ▶ if ($Config{userelocatableinc} && $data->{relocate_as})
Branch: 1 branch
BranchTrueFalseTotal
if ($ExtUtils::Packlist::Config{"userelocatableinc"} and $data->{"relocate_as"}) 0 1911 1911
Condition33%1/3
$ExtUtils::Packlist::Config{"userelocatableinc"} and $data->{"relocate_as"}
!ll&&!rl&&r
191100
MC/DC0%0/2
$ExtUtils::Packlist::Config{"userelocatableinc"} and $data->{"relocate_as"}
$ExtUtils::Packlist::Config{"userelocatableinc"} $data->{"relocate_as"}
Truth table33%1/3
A and B
A= $ExtUtils::Packlist::Config{"userelocatableinc"}B= $data->{"relocate_as"}
ABresult
0X0
100
111
138 {
139 0 require File::Spec;
140 0 require Cwd;
141 0 my ($vol, $dir) = File::Spec->splitpath($packfile);
142 0 my $newpath = File::Spec->catpath($vol, $dir, $data->{relocate_as});
143 0 $key = Cwd::realpath($newpath);
144 }
145 }
146 57285 $key =~ s!/\./!/!g; # Some .packlists have spurious '/./' bits in the paths
147 57285 $self->{data}->{$key} = $data;
148 }
149 1003 close($fh);
150 }
151  
152 sub write($;$)
153 {
154 19 ▶my ($self, $packfile) = @_;
Subroutine write: called CC=13 SCAR=32.4
Pod documented
155 19 ▶$self = tied(%$self) || $self;
Condition66%2/3
tied %$self || $self
l!l&&r!l&&!r
1540
MC/DC0%0/2
tied %$self || $self
tied %$self $self
Truth table66%2/3
A || B
A= tied %$selfB= $self
ABresult
1X1
011
000
156 19 ▶if (defined($packfile)) { $self->{packfile} = $packfile; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packfile) { } 18 1 19
157 1 else { $packfile = $self->{packfile}; }
158 19 ▶Carp::croak("No packlist filename specified") if (! defined($packfile));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packfile 1 18 19
159 18 my $fh = mkfh();
160 18 ▶open($fh, ">$packfile") || Carp::croak("Can't open file $packfile: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$packfile" or Carp::croak("Can't open file ${packfile}: $!") 1 17 18
161 17 foreach my $key (sort(keys(%{$self->{data}})))
162 {
163 28 my $data = $self->{data}->{$key};
164 28 ▶ if ($Config{userelocatableinc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ExtUtils::Packlist::Config{"userelocatableinc"}) 0 28 28
165 0 ▶ $Relocations ||= __find_relocations();
Condition0%0/3
$ExtUtils::Packlist::Relocations ||= __find_relocations()
l!l&&r!l&&!r
000
MC/DC0%0/2
$ExtUtils::Packlist::Relocations ||= __find_relocations()
$ExtUtils::Packlist::Relocations __find_relocations()
Truth table0%0/3
A ||= B
A= $ExtUtils::Packlist::RelocationsB= __find_relocations()
ABresult
1X1
011
000
166 0 ▶ if ($packfile =~ $Relocations) {
Branch: 1 branch
BranchTrueFalseTotal
if ($packfile =~ /$ExtUtils::Packlist::Relocations/) 0 0 0
167 # We are writing into a subdirectory of a run-time relocated
168 # path. Figure out if the this file is also within a subdir.
169 0 my $prefix = $1;
170 0 ▶ if (File::Spec->no_upwards(File::Spec->abs2rel($key, $prefix)))
Branch: 1 branch
BranchTrueFalseTotal
if ("File::Spec"->no_upwards("File::Spec"->abs2rel($key, $prefix))) 0 0 0
171 {
172 # The relocated path is within the found prefix
173 0 my $packfile_prefix;
174 0 (undef, $packfile_prefix)
175 = File::Spec->splitpath($packfile);
176  
177 0 my $relocate_as
178 = File::Spec->abs2rel($key, $packfile_prefix);
179  
180 0 ▶ if (!ref $data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $data) 0 0 0
181 0 $data = {};
182 }
183 0 $data->{relocate_as} = $relocate_as;
184 }
185 }
186 }
187 28 print $fh ("$key");
188 28 ▶ if (ref($data))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) 1 27 28
189 {
190 1 foreach my $k (sort(keys(%$data)))
191 {
192 2 print $fh (" $k=$data->{$k}");
193 }
194 }
195 28 print $fh ("\n");
196 }
197 17 close($fh);
198 }
199  
200 sub validate($;$)
201 {
202 2 ▶my ($self, $remove) = @_;
Subroutine validate: called CC=5 SCAR=16.2
Pod documented
203 2 ▶$self = tied(%$self) || $self;
Condition33%1/3
tied %$self || $self
l!l&&r!l&&!r
020
MC/DC0%0/2
tied %$self || $self
tied %$self $self
Truth table33%1/3
A || B
A= tied %$selfB= $self
ABresult
1X1
011
000
204 2 my @missing;
205 2 foreach my $key (sort(keys(%{$self->{data}})))
206 {
207 4 ▶ if (! -e $key)
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $key) 2 2 4
208 {
209 2 push(@missing, $key);
210 2 ▶ delete($self->{data}{$key}) if ($remove);
Branch: 1 branch
BranchTrueFalseTotal
if $remove 1 1 2
211 }
212 }
213 2 return(@missing);
214 }
215  
216 sub packlist_file($)
217 {
218 2 ▶my ($self) = @_;
Subroutine packlist_file: called CC=2 SCAR=7.0
Pod documented
219 2 ▶$self = tied(%$self) || $self;
Condition66%2/3
tied %$self || $self
l!l&&r!l&&!r
110
MC/DC0%0/2
tied %$self || $self
tied %$self $self
Truth table66%2/3
A || B
A= tied %$selfB= $self
ABresult
1X1
011
000
220 2 return($self->{packfile});
221 }
222  
223 4 1;
224  
225 __END__
« blib/lib/ExtUtils/Installed.pm ↑ Summary Makefile.PL »