blib/lib/Module/MetaInfo/_Extractor.pm

filter: Statementstmt 95.1% 78 / 82 Branchbran 67.6% 23 / 34 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 10 / 10 Podpod 40.0% 2 / 5 totaltotal 80.8% 118 / 146 CC 19 SCAR 17.4
CC
19
Cov
85%
setup
10.5
scratch_dir
5.0
verbose
5.0
CRAP 5.7
« blib/lib/Module/MetaInfo/ModList.pm ↑ Summary blib/lib/Module/MetaInfo/DirTree.pm »
1 package Module::MetaInfo::_Extractor;
2 4 $VERSION = "0.01";
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Module::MetaInfo::_Extractor - Base class for perl modules to get metainfo
12  
13 =head1 USAGE
14  
15 use Module::MetaInfo::_Extractor;
16 $mod=new Module::MetaInfo::_Extractor(perl-module-file.tar.gz);
17 $desc=$mod->description();
18  
19 =head1 DESCRIPTION
20  
21 This module provides untility functions for C<Module::MetaInfo>
22 classes which need to extract the perl module in order to get their
23 meta information from it.
24  
25 =head1 FUNCTIONS
26  
27 =cut
28  
29 my $scratch_dir="/tmp/perl-metainfo-temp."
30 4 ▶ . ( $ENV{LOGNAME} ? $ENV{LOGNAME} : ( $ENV{USER} ? $ENV{USER} : "dumb" ) );
Branch: 2 branches
BranchTrueFalseTotal
$ENV{'LOGNAME'} ? : 0 4 4
$ENV{'USER'} ? : 0 4 4
31  
32 4 my $verbose=0;
33  
34 =head1 Module::MetaInfo::_Extractor::new(<distfilename>)
35  
36 new creates the object and initialises it. The argument is the path
37 of the perl module distribution file.
38  
39 =cut
40  
41 14 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
42 14 my $s = shift;
43 14 my $distname = shift;
44 14 ▶ my $class = ref($s) || $s;
Condition33%1/3
ref $s || $s
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $s || $s
ref $s $s
Truth table33%1/3
A || B
A= ref $sB= $s
ABresult
1X1
011
000
45 14 my $self={};
46  
47 14 my $distfile = $distname;
48 14 ▶ $distfile =~ m,^/, || ( $distfile = cwd . '/' . $distfile );
Branch: 1 branch
BranchTrueFalseTotal
$distfile =~ m[^/] or $distfile = cwd() . '/' . $distfile 0 14 14
49 14 $distname =~ s,^.*/,,;
50 14 my $package_name = $distname;
51 14 $package_name =~ s,(.tar.gz)|(.tgz),,;
52 14 $self->{distfile}=$distfile;
53 14 $self->{distname}=$distname;
54 14 $self->{package_name}=$package_name;
55 14 $self->{_scratch_dir}=\$scratch_dir;
56 14 $self->{_verbose}=\$verbose;
57 14 return bless $self, $class;
58 }
59  
60 =head1 $thing->::verbose() $thing->::scratch_dir()
61  
62 These functions affect class settings (or if called for an object,
63 only the settings of the object: afterwards that object will ignore
64 changes to the class settings).
65  
66 Currently implemented are verbose which prints debugging info and
67 scratch_dir which sets the directory to be used for unpacking perl
68 modules.
69  
70 =cut
71  
72 #N.B. $self->{scratch_dir} is a reference to the variable holding the
73 #location of he scratch directory.
74  
75 8 ▶sub scratch_dir {
Subroutine scratch_dir: called CC=5 SCAR=16.1
Pod undocumented
76 8 my $self = shift;
77 8 my $val = shift;
78 8 ▶ confess "usage: thing->scratch_dir(level)" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
79 8 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 2 6 8
80 2 ▶ return ${$self->{"_scratch_dir"}} unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 1 1 2
81 1 $self->{"_scratch_dir"} = \$val; # just myself
82 1 return ${$self->{"_scratch_dir"}};
83 } else {
84 6 ▶ return $scratch_dir unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 3 3 6
85 3 $scratch_dir = $val; # whole class
86 3 return $scratch_dir;
87 }
88 0 die "not reached";
89 }
90  
91 #N.B. $self->{verbose} is a reference to the variable holding the
92 #location of he scratch directory.
93 8 ▶sub verbose {
Subroutine verbose: called CC=5 SCAR=16.1
Pod undocumented
94 8 my $self = shift;
95 8 my $val = shift;
96 8 ▶ confess "usage: thing->verbose(level)" if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
97 8 ▶ if (ref($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 5 8
98 3 ▶ return ${$self->{"_verbose"}} unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 2 1 3
99 1 $self->{"_verbose"} = \$val; # just myself
100 1 return ${$self->{"_verbose"}};
101 } else {
102 5 ▶ return $verbose unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 2 3 5
103 3 $verbose = $val; # whole class
104 3 return $verbose;
105 }
106 0 die "not reached";
107 }
108  
109 =head2 $self->setup()
110  
111 Setup prepares us for getting meta information. In the current
112 implementation it does this by unpacking the distribution file. In a
113 'future version this function may do nothing and issue a warning, but
114 it will continute to exist into the forseeable future.
115  
116 The only reason to call this function now is to trap errors from it
117 separately or if you delete the setup directory and want it's contents
118 re-created.
119  
120 =cut
121  
122 6 ▶sub setup {
Subroutine setup: called CC=9 SCAR=23.5
Pod documented
123 6 my $self=shift;
124 6 my $old_dir=cwd;
125 6 my $scratch=${$self->{_scratch_dir}};
126 6 ▶ croak "scratch dir not defined " unless defined ${$self->{_scratch_dir}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined ${$$self{"_scratch_dir"};} 0 6 6
127 6 ▶ -e $scratch && (! -d _ )
Branch: 1 branch
BranchTrueFalseTotal
-e $scratch and not -d _ and croak("scratch dir $scratch exists but is not a directory") 0 6 6
Condition66%2/3
-e $scratch and not -d _
!ll&&!rl&&r
330
MC/DC0%0/2
-e $scratch and not -d _
-e $scratch not -d _
Truth table66%2/3
A and not(B)
A= -e $scratchB= not -d _
ABresult
0X0
100
111
128 && croak "scratch dir $scratch exists but is not a directory";
129 6 ▶ -e _ or mkdir $scratch_dir
Branch: 1 branch
BranchTrueFalseTotal
-e _ or mkdir $scratch_dir or die "can't create scratch directory $scratch_dir" . $! 6 0 6
Condition66%2/3
-e _ or mkdir $scratch_dir
l!l&&r!l&&!r
330
MC/DC0%0/2
-e _ or mkdir $scratch_dir
-e _ mkdir $scratch_dir
Truth table66%2/3
A or B
A= -e _B= mkdir $scratch_dir
ABresult
1X1
011
000
130 or die "can't create scratch directory $scratch_dir" . $!;
131  
132 #FIXME: check for correct ownership of scratchdir?? probably just that
133 #we have write access since we will work inside our own sub directories
134 #inside it, however there could be a danger of race conditions if we use
135 #someone elses directory then they rename something down the tree??
136  
137 6 my $unpack_dir=${$self->{_scratch_dir}} . '/' . $self->{distname};
138 #FIXME: we should actually check that there is an unpacked module
139 $self->{expand_dir}=
140 6 ${$self->{_scratch_dir}} .'/'. $self->{distname}
141 6 .'/'. $self->{package_name};
142 6 $self->{setup}=1;
143 -d $unpack_dir
144 0 ▶ && do { warn "setup called but directory $unpack_dir exists"; return; };
Branch: 1 branch
BranchTrueFalseTotal
-d $unpack_dir and do { warn "setup called but directory $unpack_dir exists"; return } 0 6 6
145 6 ▶ -e $unpack_dir
Branch: 1 branch
BranchTrueFalseTotal
-e $unpack_dir and die "file exists where setup directory should be $unpack_dir" 0 6 6
146 && die "file exists where setup directory should be $unpack_dir";
147 6 mkdir $unpack_dir;
148 #FIXME: check exit status etc... think about all kinds of tar... use
149 #perl TAR module??
150 6 system 'tar', 'xzCf', $unpack_dir, $self->{distfile};
151 6 ▶ -d $unpack_dir
Branch: 1 branch
BranchTrueFalseTotal
-d $unpack_dir or die "unpacking perl module didn't create the right name." 6 0 6
152 || die "unpacking perl module didn't create the right name.";
153 }
154  
155 =head2 name
156  
157 returns the packages name, or at least an approximation
158  
159 =cut
160  
161 1 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
162 1 my $self=shift;
163 1 return $self->{package_name};
164 }
165  
166  
167 =head1 COPYRIGHT
168  
169 You may distribute under the terms of either the GNU General
170 Public License or the Artistic License, as specified in the
171 Perl README.
172  
173 =head1 BUGS
174  
175 We trust the path to the scratch directory. Make sure that nobody
176 that you don't trust can control any of the directories up to and
177 including the scratch directory. There shoudld be an option to test
178 that the ownership and control is clear.
179  
180 =head1 AUTHOR
181  
182 Michael De La Rue.
183  
184 =head1 SEE ALSO
185  
186 L<Module::MetaInfo> L<pm-metainfo>
187  
188 =cut
189  
190 4 42;
« blib/lib/Module/MetaInfo/ModList.pm ↑ Summary blib/lib/Module/MetaInfo/DirTree.pm »