blib/lib/CPAN/InfoObj.pm

filter: Statementstmt 36.0% 48 / 133 Branchbran 21.8% 14 / 64 Conditioncond 27.2% 3 / 11 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 62.5% 10 / 16 Podpod 0.0% 0 / 12 totaltotal 31.4% 76 / 242 CC 77 SCAR 41.8
CC
77
Cov
31%
as_string
129.8
as_string
129.8
safe_chdir
55.9
CRAP 65.1
« blib/lib/CPAN/Version.pm ↑ Summary blib/lib/CPAN/FTP/netrc.pm »
1 # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*-
2 # vim: ts=4 sts=4 sw=4:
3 package CPAN::InfoObj;
4 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 26 ▶use CPAN::Debug;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 @CPAN::InfoObj::ISA = qw(CPAN::Debug);
8  
9 26 ▶use Cwd qw(chdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 26 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 $VERSION
13 26 );
14 26 $VERSION = "5.5";
15  
16 352 ▶sub ro {
Subroutine ro: called CC=2 SCAR=9.2
Pod undocumented
17 0 ▶ my $self = shift;
Subroutine ro: not called CC=2 SCAR=9.2
Pod undocumented
18 0 ▶ exists $self->{RO} and return $self->{RO};
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{"RO"} and return $self->{"RO"} 171 181 352
exists $self->{"RO"} and return $self->{"RO"} 0 0 0
19 }
20  
21 #-> sub CPAN::InfoObj::cpan_userid
22 0 ▶sub cpan_userid {
Subroutine cpan_userid: not called CC=3 SCAR=24.8
Pod undocumented
23 0 ▶ my $self = shift;
Subroutine cpan_userid: not called CC=3 SCAR=24.8
Pod undocumented
24 0 my $ro = $self->ro;
25 0 ▶ if ($ro) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ro) { } 0 0 0
if ($ro) { } 0 0 0
26 0 ▶ return $ro->{CPAN_USERID} || "N/A";
Condition0%0/4
$ro->{'CPAN_USERID'} || 'N/A'
l!l
00
$ro->{'CPAN_USERID'} || 'N/A'
l!l
00
MC/DC0%0/1
$ro->{'CPAN_USERID'} || 'N/A'
$ro->{'CPAN_USERID'}
MC/DC0%0/1
$ro->{'CPAN_USERID'} || 'N/A'
$ro->{'CPAN_USERID'}
Truth table0%0/2
A
A= $ro->{'CPAN_USERID'}
Aresult
11
00
Truth table0%0/2
A
A= $ro->{'CPAN_USERID'}
Aresult
11
00
27 } else {
28 0 $self->debug("ID[$self->{ID}]");
29 # N/A for bundles found locally
30 0 return "N/A";
31 }
32 }
33  
34 304 ▶sub id { shift->{ID}; }
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
35  
36 #-> sub CPAN::InfoObj::new ;
37 96 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
38 96 my $this = bless {}, shift;
39 96 %$this = @_;
40 96 $this
41 }
42  
43 # The set method may only be used by code that reads index data or
44 # otherwise "objective" data from the outside world. All session
45 # related material may do anything else with instance variables but
46 # must not touch the hash under the RO attribute. The reason is that
47 # the RO hash gets written to Metadata file and is thus persistent.
48  
49 #-> sub CPAN::InfoObj::safe_chdir ;
50 35 ▶sub safe_chdir {
Subroutine safe_chdir: called CC=10 SCAR=40.2
Pod undocumented
51 35 my($self,$todir) = @_;
52 # we die if we cannot chdir and we are debuggable
53 35 ▶ Carp::confess("safe_chdir called without todir argument")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $todir and length $todir 0 35 35
Condition33%1/3
defined $todir and length $todir
!ll&&!rl&&r
0035
MC/DC0%0/2
defined $todir and length $todir
defined $todir length $todir
Truth table33%1/3
A and B
A= defined $todirB= length $todir
ABresult
0X0
100
111
54 unless defined $todir and length $todir;
55 35 ▶ if (chdir $todir) {
Branch: 1 branch
BranchTrueFalseTotal
if (CPAN::InfoObj::chdir($todir)) { } 35 0 35
56 35 ▶ $self->debug(sprintf "changed directory to %s", CPAN::anycwd())
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 35 35
57 if $CPAN::DEBUG;
58 } else {
59 0 ▶ if (-e $todir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $todir) { } 0 0 0
60 0 ▶ unless (-x $todir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $todir) 0 0 0
61 0 ▶ unless (chmod 0755, $todir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chmod 0755, $todir) 0 0 0
62 0 my $cwd = CPAN::anycwd();
63 0 $CPAN::Frontend->mywarn("I have neither the -x permission nor the ".
64 "permission to change the permission; cannot ".
65 "chdir to '$todir'\n");
66 0 $CPAN::Frontend->mysleep(5);
67 0 $CPAN::Frontend->mydie(qq{Could not chdir from cwd[$cwd] }.
68 qq{to todir[$todir]: $!});
69 }
70 }
71 } else {
72 0 $CPAN::Frontend->mydie("Directory '$todir' has gone. Cannot continue.\n");
73 }
74 0 ▶ if (chdir $todir) {
Branch: 1 branch
BranchTrueFalseTotal
if (CPAN::InfoObj::chdir($todir)) { } 0 0 0
75 0 ▶ $self->debug(sprintf "changed directory to %s", CPAN::anycwd())
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::DEBUG 0 0 0
76 if $CPAN::DEBUG;
77 } else {
78 0 my $cwd = CPAN::anycwd();
79 0 $CPAN::Frontend->mydie(qq{Could not chdir from cwd[$cwd] }.
80 qq{to todir[$todir] (a chmod has been issued): $!});
81 }
82 }
83 }
84  
85 #-> sub CPAN::InfoObj::set ;
86 101 ▶sub set {
Subroutine set: called CC=4 SCAR=14.2
Pod undocumented
87 101 my($self,%att) = @_;
88 101 my $class = ref $self;
89  
90 # This must be ||=, not ||, because only if we write an empty
91 # reference, only then the set method will write into the readonly
92 # area. But for Distributions that spring into existence, maybe
93 # because of a typo, we do not like it that they are written into
94 # the readonly area and made permanent (at least for a while) and
95 # that is why we do not "allow" other places to call ->set.
96 101 ▶ unless ($self->id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->id) 0 101 101
97 0 CPAN->debug("Bug? Empty ID, rejecting");
98 0 return;
99 }
100 my $ro = $self->{RO} =
101 101 ▶ $CPAN::META->{readonly}{$class}{$self->id} ||= {};
Condition100%2/2
$CPAN::META->{"readonly"}{$class}{$self->id} ||= {}
l!l
893
MC/DC100%1/1
$CPAN::META->{"readonly"}{$class}{$self->id} ||= {}
$CPAN::META->{"readonly"}{$class}{$self->id}
Truth table100%2/2
A
A= $CPAN::META->{"readonly"}{$class}{$self->id}
Aresult
11
00
102  
103 101 ▶ while (my($k,$v) = each %att) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %att) 281 101 382
104 281 $ro->{$k} = $v;
105 }
106 }
107  
108 #-> sub CPAN::InfoObj::as_glimpse ;
109 0 ▶sub as_glimpse {
Subroutine as_glimpse: not called CC=2 SCAR=17.9
Pod undocumented
110 0 my($self) = @_;
111 0 my(@m);
112 0 my $class = ref($self);
113 0 $class =~ s/^CPAN:://;
114 0 ▶ my $id = $self->can("pretty_id") ? $self->pretty_id : $self->{ID};
Branch: 1 branch
BranchTrueFalseTotal
$self->can('pretty_id') ? : 0 0 0
115 0 push @m, sprintf "%-15s %s\n", $class, $id;
116 0 join "", @m;
117 }
118  
119 #-> sub CPAN::InfoObj::as_string ;
120 1 ▶sub as_string {
Subroutine as_string: called CC=18 SCAR=48.7
Pod undocumented
121 1 my($self) = @_;
122 1 my(@m);
123 1 my $class = ref($self);
124 1 $class =~ s/^CPAN:://;
125 1 push @m, $class, " id = $self->{ID}\n";
126 1 my $ro;
127 1 ▶ unless ($ro = $self->ro) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ro = $self->ro) 0 1 1
128 0 ▶ if (substr($self->{ID},-1,1) eq ".") { # directory
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{'ID'}, -1, 1) eq '.') { } 0 0 0
129 0 $ro = +{};
130 } else {
131 0 $CPAN::Frontend->mywarn("Unknown object $self->{ID}\n");
132 0 $CPAN::Frontend->mysleep(5);
133 0 return;
134 }
135 }
136 1 for (sort keys %$ro) {
137 # next if m/^(ID|RO)$/;
138 2 my $extra = "";
139 2 ▶ if ($_ eq "CPAN_USERID") {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq 'CPAN_USERID') { } 0 2 2
elsif ($_ eq 'FULLNAME') { } 1 1 2
140 0 $extra .= " (";
141 0 $extra .= $self->fullname;
142 0 my $email; # old perls!
143 0 ▶ if ($email = $CPAN::META->instance("CPAN::Author",
Branch: 1 branch
BranchTrueFalseTotal
if ($email = $CPAN::META->instance('CPAN::Author', $self->cpan_userid)->email) { } 0 0 0
144 $self->cpan_userid
145 )->email) {
146 0 $extra .= " <$email>";
147 } else {
148 0 $extra .= " <no email>";
149 }
150 0 $extra .= ")";
151 } elsif ($_ eq "FULLNAME") { # potential UTF-8 conversion
152 1 push @m, sprintf " %-12s %s\n", $_, $self->fullname;
153 1 next;
154 }
155 1 ▶ next unless defined $ro->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ro->{$_} 0 1 1
156 1 push @m, sprintf " %-12s %s%s\n", $_, $ro->{$_}, $extra;
157 }
158 1 KEY: for (sort keys %$self) {
159 2 ▶ next if m/^(ID|RO)$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(ID|RO)$/ 2 0 2
160 0 ▶ unless (defined $self->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{$_}) 0 0 0
161 0 delete $self->{$_};
162 0 next KEY;
163 }
164 0 ▶ if (ref($self->{$_}) eq "ARRAY") {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{$_} eq 'ARRAY') { } 0 0 0
elsif (ref $self->{$_} eq 'HASH') { } 0 0 0
165 0 push @m, sprintf " %-12s %s\n", $_, "@{$self->{$_}}";
166 } elsif (ref($self->{$_}) eq "HASH") {
167 0 my $value;
168 0 ▶ if (/^CONTAINSMODS$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^CONTAINSMODS$/) { } 0 0 0
elsif (/^prereq_pm$/) { } 0 0 0
169 0 $value = join(" ",sort keys %{$self->{$_}});
170 } elsif (/^prereq_pm$/) {
171 0 my @value;
172 0 my $v = $self->{$_};
173 0 for my $x (sort keys %$v) {
174 0 my @svalue;
175 0 for my $y (sort keys %{$v->{$x}}) {
176 0 push @svalue, "$y=>$v->{$x}{$y}";
177 }
178 0 ▶ push @value, "$x\:" . join ",", @svalue if @svalue;
Branch: 1 branch
BranchTrueFalseTotal
if @svalue 0 0 0
179 }
180 0 $value = join ";", @value;
181 } else {
182 0 $value = $self->{$_};
183 }
184 0 push @m, sprintf(
185 " %-12s %s\n",
186 $_,
187 $value,
188 );
189 } else {
190 0 push @m, sprintf " %-12s %s\n", $_, $self->{$_};
191 }
192 }
193 1 join "", @m, "\n";
194 }
195  
196 #-> sub CPAN::InfoObj::fullname ;
197 0 ▶sub fullname {
Subroutine fullname: not called CC=1 SCAR=6.9
Pod undocumented
198 0 my($self) = @_;
199 0 $CPAN::META->instance("CPAN::Author",$self->cpan_userid)->fullname;
200 }
201  
202 #-> sub CPAN::InfoObj::dump ;
203 0 ▶sub dump {
Subroutine dump: not called CC=6 SCAR=37.4
Pod undocumented
204 0 my($self, $what) = @_;
205 0 ▶ unless ($CPAN::META->has_inst("Data::Dumper")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPAN::META->has_inst("Data::Dumper")) 0 0 0
206 0 $CPAN::Frontend->mydie("dump command requires Data::Dumper installed");
207 }
208 0 local $Data::Dumper::Sortkeys;
209 0 $Data::Dumper::Sortkeys = 1;
210 0 ▶ my $out = Data::Dumper::Dumper($what ? eval $what : $self);
Branch: 1 branch
BranchTrueFalseTotal
$what ? : 0 0 0
211 0 ▶ if (length $out > 100000) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $out > 100000) { } 0 0 0
212 0 my $fh_pager = FileHandle->new;
213 0 local($SIG{PIPE}) = "IGNORE";
214 0 ▶ my $pager = $CPAN::Config->{'pager'} || "cat";
Condition0%0/2
$CPAN::Config->{'pager'} || 'cat'
l!l
00
MC/DC0%0/1
$CPAN::Config->{'pager'} || 'cat'
$CPAN::Config->{'pager'}
Truth table0%0/2
A
A= $CPAN::Config->{'pager'}
Aresult
11
00
215 0 ▶ $fh_pager->open("|$pager")
Branch: 1 branch
BranchTrueFalseTotal
$fh_pager->open("|$pager") or die "Could not open pager ${pager}: $!" 0 0 0
216 or die "Could not open pager $pager\: $!";
217 0 $fh_pager->print($out);
218 0 close $fh_pager;
219 } else {
220 0 $CPAN::Frontend->myprint($out);
221 }
222 }
223  
224 26 1;
« blib/lib/CPAN/Version.pm ↑ Summary blib/lib/CPAN/FTP/netrc.pm »