| 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
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $s || $s
ref $s
$s
Truth table33%1/3
A || B
A= ref $sB= $s
| |||||||||||||||||||||||||||||
| 45 | 14 | my $self={}; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 14 | my $distfile = $distname; | |||||||||||||||||||||||||||
| 48 | 14 | ▶ | $distfile =~ m,^/, || ( $distfile = cwd . '/' . $distfile ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | 8 | ▶ | if (ref($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 2 | ▶ | return ${$self->{"_scratch_dir"}} unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 97 | 8 | ▶ | if (ref($self)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 3 | ▶ | return ${$self->{"_verbose"}} unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 1 | $self->{"_verbose"} = \$val; # just myself | |||||||||||||||||||||||||||
| 100 | 1 | return ${$self->{"_verbose"}}; | |||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||
| 102 | 5 | ▶ | return $verbose unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 127 | 6 | ▶ | -e $scratch && (! -d _ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e $scratch and not -d _
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 _
| |||||||||||||||||||||||||||||
| 128 | && croak "scratch dir $scratch exists but is not a directory"; | ||||||||||||||||||||||||||||
| 129 | 6 | ▶ | -e _ or mkdir $scratch_dir | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
-e _ or mkdir $scratch_dir
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 145 | 6 | ▶ | -e $unpack_dir | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||