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
1 package ExtUtils::Packlist;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use Carp qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 our $Relocations;
7 5 our $VERSION = '2.22';
8 5 $VERSION = eval $VERSION;
9  
10 # Used for generating filehandle globs. IO::File might not be available!
11 5 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 1055 ▶{
Subroutine mkfh: called CC=1 SCAR=0.0
Pod documented
25 5 ▶no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1055 local $^W;
27 1055 my $fh = \*{$fhname++};
28 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1055 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 0 ▶{
Subroutine __find_relocations: not called CC=4 SCAR=30.0
45 0 my %paths;
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 1047 ▶{
Subroutine new: called CC=2 SCAR=7.2
Pod documented
60 1047 my ($class, $packfile) = @_;
61 1047 ▶$class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010470
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 1047 my %self;
63 1047 tie(%self, $class, $packfile);
64 1047 return(bless(\%self, $class));
65 }
66  
67 sub TIEHASH
68 1048 ▶{
Subroutine TIEHASH: called CC=3 SCAR=11.0
69 1048 my ($class, $packfile) = @_;
70 1048 my $self = { packfile => $packfile };
71 1048 bless($self, $class);
72 1048 ▶$self->read($packfile) if (defined($packfile) && -f $packfile);
Branch: 1 branch
BranchTrueFalseTotal
if defined $packfile and -f $packfile 1018 30 1048
Condition100%3/3
defined $packfile and -f $packfile
!ll&&!rl&&r
2191018
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 1048 return($self);
74 }
75  
76 sub STORE
77 24 ▶{
Subroutine STORE: called CC=1 SCAR=0.0
78 24 $_[0]->{data}->{$_[1]} = $_[2];
79 }
80  
81 sub FETCH
82 24 ▶{
Subroutine FETCH: called CC=1 SCAR=0.0
83 24 return($_[0]->{data}->{$_[1]});
84 }
85  
86 sub FIRSTKEY
87 1 ▶{
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
88 1 my $reset = scalar(keys(%{$_[0]->{data}}));
89 1 return(each(%{$_[0]->{data}}));
90 }
91  
92 sub NEXTKEY
93 1 ▶{
Subroutine NEXTKEY: called CC=1 SCAR=0.0
94 1 return(each(%{$_[0]->{data}}));
95 }
96  
97 sub EXISTS
98 1020 ▶{
Subroutine EXISTS: called CC=1 SCAR=0.0
99 1020 return(exists($_[0]->{data}->{$_[1]}));
100 }
101  
102 sub DELETE
103 1 ▶{
Subroutine DELETE: called CC=1 SCAR=0.0
104 1 return(delete($_[0]->{data}->{$_[1]}));
105 }
106  
107 sub CLEAR
108 1 ▶{
Subroutine CLEAR: called CC=1 SCAR=0.0
109 1 %{$_[0]->{data}} = ();
110 }
111  
112 sub DESTROY
113 0 ▶{
Subroutine DESTROY: not called CC=1 SCAR=0.0
114 }
115  
116 sub read($;$)
117 1035 ▶{
Subroutine read: called CC=9 SCAR=22.7
Pod documented
118 1035 my ($self, $packfile) = @_;
119 1035 ▶$self = tied(%$self) || $self;
Condition66%2/3
tied %$self || $self
l!l&&r!l&&!r
1410210
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 1035 ▶if (defined($packfile)) { $self->{packfile} = $packfile; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packfile) { } 1034 1 1035
122 1 else { $packfile = $self->{packfile}; }
123 1035 ▶Carp::croak("No packlist filename specified") if (! defined($packfile));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packfile 1 1034 1035
124 1034 my $fh = mkfh();
125 1034 ▶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}: $!") 1033 1 1034
126 1033 $self->{data} = {};
127 1033 my ($line);
128 1033 ▶while (defined($line = <$fh>))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 57483 1033 58516
129 {
130 57483 chomp $line;
131 57483 my ($key, $data) = $line;
132 57483 ▶ if ($key =~ /^(.*?)( \w+=.*)$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /^(.*?)( \w+=.*)$/) 1911 55572 57483
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 57483 $key =~ s!/\./!/!g; # Some .packlists have spurious '/./' bits in the paths
147 57483 $self->{data}->{$key} = $data;
148 }
149 1033 close($fh);
150 }
151  
152 sub write($;$)
153 20 ▶{
Subroutine write: called CC=13 SCAR=32.4
Pod documented
154 20 my ($self, $packfile) = @_;
155 20 ▶$self = tied(%$self) || $self;
Condition66%2/3
tied %$self || $self
l!l&&r!l&&!r
1640
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 20 ▶if (defined($packfile)) { $self->{packfile} = $packfile; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $packfile) { } 19 1 20
157 1 else { $packfile = $self->{packfile}; }
158 20 ▶Carp::croak("No packlist filename specified") if (! defined($packfile));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $packfile 1 19 20
159 19 my $fh = mkfh();
160 19 ▶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}: $!") 18 1 19
161 18 foreach my $key (sort(keys(%{$self->{data}})))
162 {
163 34 my $data = $self->{data}->{$key};
164 34 ▶ if ($Config{userelocatableinc}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ExtUtils::Packlist::Config{"userelocatableinc"}) 0 34 34
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 34 print $fh ("$key");
188 34 ▶ if (ref($data))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data) 1 33 34
189 {
190 1 foreach my $k (sort(keys(%$data)))
191 {
192 2 print $fh (" $k=$data->{$k}");
193 }
194 }
195 34 print $fh ("\n");
196 }
197 18 close($fh);
198 }
199  
200 sub validate($;$)
201 2 ▶{
Subroutine validate: called CC=5 SCAR=16.2
Pod documented
202 2 my ($self, $remove) = @_;
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 2 ▶{
Subroutine packlist_file: called CC=2 SCAR=7.0
Pod documented
218 2 my ($self) = @_;
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 5 1;
224  
225 __END__
« blib/lib/ExtUtils/Installed.pm ↑ Summary