blib/lib/ExtUtils/Packlist.pm

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