blib/lib/Perl/Installed.pm

filter: Statementstmt 58.8% 30 / 51 Branchbran 35.7% 5 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 4 / 4 totaltotal 57.1% 44 / 77 CC 9 SCAR 24.1
CC
9
Cov
54%
files
30.0
new
4.2
_config_init
2.0
CRAP 11.1
↑ Summary
1 ###########################################
2 package Perl::Installed;
3 ###########################################
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 #use Log::Log4perl qw(:easy);
8 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = "0.01";
11  
12 ###########################################
13 2 ▶sub new {
Subroutine new: called CC=4 SCAR=14.5
Pod documented
14 ###########################################
15 2 my($class, %options) = @_;
16  
17 2 my $self = {
18 %options,
19 };
20  
21 2 ▶ if(! exists $self->{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"prefix"}) 1 1 2
22 1 die "Mandatory parameter 'prefix' missing";
23 }
24  
25 1 ▶ if(! -d $self->{prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $self->{"prefix"}) 0 1 1
26 0 die "Mandatory parameter 'prefix' not a directory";
27 }
28  
29 1 $self->{bindir} = File::Spec->catfile($self->{prefix}, "bin");
30 1 $self->{perldoc} = File::Spec->catfile($self->{bindir}, "perldoc");
31 1 $self->{perl} = File::Spec->catfile($self->{bindir}, "perl");
32  
33 1 ▶ if(! -f $self->{perl}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $self->{"perl"}) 0 1 1
34 0 die "perl not found under prefix $self->{prefix}/bin";
35 }
36  
37 1 bless $self, $class;
38 1 $self->_config_init();
39  
40 0 return $self;
41 }
42  
43 ###########################################
44 1 ▶sub _config_init {
Subroutine _config_init: called CC=2 SCAR=7.0
45 ###########################################
46 1 my($self) = @_;
47  
48 1 my $cmd =
49 qq#$self->{perl} -MConfig -l0e'print "\$_\\0\$Config{\$_}" # .
50 qq#for keys %Config'#;
51  
52 1 my $data = `$cmd`;
53 1 my %config = split /\0/, $data;
54 1 $self->{config} = \%config;
55  
56 $self->{packlistfile} = File::Spec->catfile($self->{config}->{archlib},
57 1 ".packlist");
58  
59 1 ▶ if($self->{config}->{version} !~ /\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"config"}{"version"} =~ /\d/) 1 0 1
60 1 die "Loading config failed";
61 }
62 }
63  
64 ###########################################
65 0 ▶sub config {
Subroutine config: not called CC=1 SCAR=6.9
Pod documented
66 ###########################################
67 0 my($self) = @_;
68  
69 0 return $self->{config};
70 }
71  
72 ###########################################
73 0 ▶sub files {
Subroutine files: not called CC=5 SCAR=34.0
Pod documented
74 ###########################################
75 0 my($self) = @_;
76  
77 0 ▶ if(! -f $self->{packlistfile}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $self->{"packlistfile"}) 0 0 0
78 #ERROR "Package file $packfile doesn't exist";
79 0 return undef;
80 }
81  
82 0 my @packlist;
83 # Read a .packlist file of an installed perl distribution
84 # and generate the necessary yicf file/symlink lines from
85 # it.
86 #
87 # A perl packlist looks like this:
88 # /home/y/bin/libnetcfg type=file
89 # /home/y/bin/perl from=/home/y/bin/perl5.10.1 type=link
90 0 ▶ open FILE, "<$self->{packlistfile}" or
Branch: 1 branch
BranchTrueFalseTotal
open FILE, qq[<$self->{"packlistfile"}] or die qq[Cannot open $self->{"packlistfile"} ($!)] 0 0 0
91 die "Cannot open $self->{packlistfile} ($!)";
92  
93 0 ▶ while(<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 0 0 0
94  
95 0 my %opts;
96  
97 0 my($file, @options) = split ' ', $_;
98  
99 0 for my $opt (@options) {
100 0 my($key, $value) = split /=/, $opt;
101 0 $opts{$key} = $value;
102 }
103  
104 0 push @packlist, {path => $file, %opts};
105 }
106 0 close FILE;
107  
108 0 return \@packlist;
109 }
110  
111 ###########################################
112 0 ▶sub packlistfile {
Subroutine packlistfile: not called CC=1 SCAR=6.9
Pod documented
113 ###########################################
114 0 my($self) = @_;
115  
116 0 return $self->{packlistfile};
117 }
118  
119 1 1;
120  
121 __END__
↑ Summary