| 1 | package Module::MetaInfo; | ||||||||||||||||||||
| 2 | 1 | $VERSION = "0.03"; | |||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Cwd; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Symbol; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use File::Find; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use Module::MetaInfo::AutoGuess; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use Module::MetaInfo::DirTree; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 1 | ▶ | use Module::MetaInfo::ModList; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Module::MetaInfo - Report meta information from perl module distribution files | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 USAGE | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | use Module::MetaInfo.pm; | ||||||||||||||||||||
| 23 | $mod=new Module::MetaInfo(perl-module-file.tar.gz); | ||||||||||||||||||||
| 24 | $desc=$mod->description(); | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | This module is designed to provide the primary interface to Perl meta | ||||||||||||||||||||
| 29 | information for perl module distribution files (this, however, is a | ||||||||||||||||||||
| 30 | prototype and hasn't yet been accepted by the "perl community", so | ||||||||||||||||||||
| 31 | don't count on it yet). The module is designed to allow perl modules | ||||||||||||||||||||
| 32 | to be easily and accurately packaged by other package systems such as | ||||||||||||||||||||
| 33 | RPM and DPKG. | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | The C<Module::MetaInfo> module isn't actually designed to get any meta | ||||||||||||||||||||
| 36 | information from the perl module. Instead it serves as an entry point | ||||||||||||||||||||
| 37 | to other modules which have their own way of doing that. Since there | ||||||||||||||||||||
| 38 | isn't yet any agreed way to store meta-information in perl modules | ||||||||||||||||||||
| 39 | this may not be very reliable. | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | Currently there are two ways of getting meta information: a) guessing | ||||||||||||||||||||
| 42 | from the contents of the module and b) using a directory structure | ||||||||||||||||||||
| 43 | which has not yet been accepted by the perl community. The default way | ||||||||||||||||||||
| 44 | this module works is to first try b) then try a) then to give up. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =head1 IMPLEMENTATION AND INHERITANCE.. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | This module doesn't inherit anything. Instead it simply uses three | ||||||||||||||||||||
| 49 | different classes C<Module::MetaInfo::BestGuess> | ||||||||||||||||||||
| 50 | C<Module::MetaInfo::AutoGuess> and C<Module::MetaInfo::ModList>, first | ||||||||||||||||||||
| 51 | trying functions from AutoGuess then from BestGuess and finally from | ||||||||||||||||||||
| 52 | ModList. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head1 FUNCTIONS | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head1 Module::MetaInfo::new(<dist_filename> [<modlist_filename>) | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | new creates the object and initialises it. The argument is the path | ||||||||||||||||||||
| 59 | of the perl module distribution file. | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | If you provide the perl modules list then meta information from the | ||||||||||||||||||||
| 62 | modules list will be available. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | my $scratch_dir="/tmp/perl-metainfo-temp." | ||||||||||||||||||||
| 67 | 1 | ▶ | . ( $ENV{LOGNAME} ? $ENV{LOGNAME} : ( $ENV{USER} ? $ENV{USER} : "dumb" ) ); | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | my $verbose=0; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 5 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 72 | 5 | my $s = shift; | |||||||||||||||||||
| 73 | 5 | my $distname = shift; | |||||||||||||||||||
| 74 | 5 | my $modlist = shift; | |||||||||||||||||||
| 75 | 5 | ▶ | 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
| |||||||||||||||||||||
| 76 | 5 | my $self={}; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 5 | my @metafinders = ( Module::MetaInfo::DirTree->new($distname), | |||||||||||||||||||
| 79 | Module::MetaInfo::AutoGuess->new($distname) ); | ||||||||||||||||||||
| 80 | 5 | ▶ | push @metafinders, Module::MetaInfo::ModList->new($distname,$modlist) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | if $modlist; | ||||||||||||||||||||
| 82 | 5 | $self->{metafinders} = \@metafinders; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 5 | $self->{_scratch_dir}=\$scratch_dir; | |||||||||||||||||||
| 85 | 5 | $self->{_verbose}=\$verbose; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 5 | return bless $self, $class; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =head1 $thing->::verbose() $thing->::scratch_dir() | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | These functions affect class settings (or if called for an object, | ||||||||||||||||||||
| 93 | only the settings of the object: afterwards that object will ignore | ||||||||||||||||||||
| 94 | changes to the class settings). | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Currently implemented are verbose which prints debugging info and | ||||||||||||||||||||
| 97 | scratch_dir which sets the directory to be used for unpacking perl | ||||||||||||||||||||
| 98 | modules. | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | #N.B. $self->{scratch_dir} is a reference to the variable holding the | ||||||||||||||||||||
| 103 | #location of he scratch directory. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 4 | ▶ | sub scratch_dir { | ||||||||||||||||||
|
Subroutine
scratch_dir: called CC=7 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||
| 106 | 4 | my $self = shift; | |||||||||||||||||||
| 107 | 4 | my $val = shift; | |||||||||||||||||||
| 108 | 4 | ▶ | confess "usage: thing->scratch_dir(level)" if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 4 | ▶ | if (ref($self)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | ▶ | return ${$self->{"_scratch_dir"}} unless defined $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | 0 | $self->{"_scratch_dir"} = \$val; # just myself | |||||||||||||||||||
| 112 | 0 | foreach my $mod (@{$self->{metafinders}}) { | |||||||||||||||||||
| 113 | 0 | ▶ | if ( $mod->can('scratch_dir') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 0 | $mod->scratch_dir($val); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | 0 | return ${$self->{"_scratch_dir"}}; | |||||||||||||||||||
| 118 | } else { | ||||||||||||||||||||
| 119 | 4 | ▶ | return $scratch_dir unless defined $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 4 | $scratch_dir = $val; # whole class | |||||||||||||||||||
| 121 | 4 | return $scratch_dir; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | 0 | die "not reached"; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | #N.B. $self->{verbose} is a reference to the variable holding the | ||||||||||||||||||||
| 127 | #location of he scratch directory. | ||||||||||||||||||||
| 128 | 4 | ▶ | sub verbose { | ||||||||||||||||||
|
Subroutine
verbose: called CC=7 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||
| 129 | 4 | my $self = shift; | |||||||||||||||||||
| 130 | 4 | my $val = shift; | |||||||||||||||||||
| 131 | 4 | ▶ | confess "usage: thing->verbose(level)" if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 4 | ▶ | if (ref($self)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | ▶ | return ${$self->{"_verbose"}} unless defined $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 134 | 0 | $self->{"_verbose"} = \$val; # just myself | |||||||||||||||||||
| 135 | 0 | foreach my $mod (@{$self->{metafinders}}) { | |||||||||||||||||||
| 136 | 0 | ▶ | if ( $mod->can('verbose') ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 137 | 0 | $mod->verbose($val); | |||||||||||||||||||
| 138 | } | ||||||||||||||||||||
| 139 | } | ||||||||||||||||||||
| 140 | 0 | return ${$self->{"_verbose"}}; | |||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||
| 142 | 4 | ▶ | return $verbose unless defined $val; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | 4 | $verbose = $val; # whole class | |||||||||||||||||||
| 144 | 4 | return $verbose; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | 0 | die "not reached"; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =head1 description / docs / etc... | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | These functions provide meta information. They are provided by the | ||||||||||||||||||||
| 153 | base classes. In all cases the functions will return C<undef> if they | ||||||||||||||||||||
| 154 | are unable to get meta information of that kind. If there is no | ||||||||||||||||||||
| 155 | function then MetaInfo will die (croak). If you want to work with | ||||||||||||||||||||
| 156 | different versions of MetaInfo that may implement different sets of | ||||||||||||||||||||
| 157 | functions then use C<eval> to catch the C<die>. | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | For more information about the different functions available, see the | ||||||||||||||||||||
| 160 | subsidiary packages such as C<Module::MetaInfo::AutoGuess> and | ||||||||||||||||||||
| 161 | C<Module::MetaInfo::DirTree>. | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | N.B. we will throw an exception if you call a function which isn't | ||||||||||||||||||||
| 164 | provided by any of the modules. This is important since some | ||||||||||||||||||||
| 165 | functions are only present if a modules list has been provided to new. | ||||||||||||||||||||
| 166 | Either don't call those functions unless you have provided the modules | ||||||||||||||||||||
| 167 | list or catch the exception. | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | =head1 RETURN CONVENTIONS | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | Meta information function either return a scalar (name / description) | ||||||||||||||||||||
| 172 | or an array value. If an array is returned, it will actually be | ||||||||||||||||||||
| 173 | returned as a reference to an array if the function is used in a | ||||||||||||||||||||
| 174 | scalar context. | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | In C<Module::MetaInfo.pm> the scalar return is always used so any | ||||||||||||||||||||
| 177 | modules used by it must provide this mode. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =head1 FUTURE FUNCTIONS | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | There are a number of other things which should be implemented. These | ||||||||||||||||||||
| 183 | can be guessed from looking at the possible meta-information which can | ||||||||||||||||||||
| 184 | be stored in the RPM or DPG formats, for example. Examples include: | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =over 4 | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =item * | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | copyright - GPL / as perl / redistributable / etc. | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =item * | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | application area - Database / Internet / WWW / HTTP etc. | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =item * | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | suggests - related applications | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =back | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | In many cases this data is generated currently by package building | ||||||||||||||||||||
| 203 | tools simply by using a fixed string. The function should do better | ||||||||||||||||||||
| 204 | than that in almost all cases or else it is't worth having... | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | =head1 COPYRIGHT | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | You may distribute under the terms of either the GNU General Public | ||||||||||||||||||||
| 209 | License, version 2 or (at your option) later or the Artistic License, | ||||||||||||||||||||
| 210 | as specified in the Perl README. | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | =head1 BUGS | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | Please see bugs in sub modules. Especially warnings in | ||||||||||||||||||||
| 215 | C<Module::MetaInfo::_Exctractor>. | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | =head1 AUTHOR | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | Michael De La Rue. | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | =head1 SEE ALSO | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | L<pm-metainfo> | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | =cut | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | 14 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=12 SCAR=25.4
| |||||||||||||||||||||
| 229 | 14 | (my $sub = $AUTOLOAD) =~ s/.*:://; | |||||||||||||||||||
| 230 | 14 | ▶ | $sub =~ m/^DESTROY$/ && return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 231 | 10 | my $self=shift; | |||||||||||||||||||
| 232 | 10 | ▶ | croak "Function call into Module::MetaInfo wasn't a method call" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 233 | unless ref $self; | ||||||||||||||||||||
| 234 | 10 | my $tried=0; | |||||||||||||||||||
| 235 | 10 | my $return=undef; | |||||||||||||||||||
| 236 | 10 | FINDER: foreach my $mod (@{$self->{metafinders}}) { | |||||||||||||||||||
| 237 | 21 | ▶ | print "try $sub in " . ref ($mod) . "\n" if ${$self->{'_verbose'}}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 238 | 21 | ▶ | if ( $mod->can($sub) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 239 | 17 | $tried++; | |||||||||||||||||||
| 240 | #how should I cascade the effect of wantarray efficiently? | ||||||||||||||||||||
| 241 | 17 | my $return=$mod->$sub(); | |||||||||||||||||||
| 242 | 17 | ▶ | if (defined $return) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 243 | 9 | my $ref=ref $return; | |||||||||||||||||||
| 244 | 9 | ▶ | if ($ref) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 245 | 3 | ▶ | die "meta info functions should only return array refs" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 246 | unless $ref=~m/^ARRAY/; | ||||||||||||||||||||
| 247 | 3 | ▶ | return wantarray ? @$return : $return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 248 | } | ||||||||||||||||||||
| 249 | 6 | return $return; | |||||||||||||||||||
| 250 | } | ||||||||||||||||||||
| 251 | } | ||||||||||||||||||||
| 252 | } | ||||||||||||||||||||
| 253 | print STDERR "no metainfo module could provide $sub\n" | ||||||||||||||||||||
| 254 | 1 | ▶ | if ${$self->{'_verbose'}}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 255 | 1 | ▶ | return undef if $tried; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 256 | 0 | die "No function $sub defined for retrieving meta information"; | |||||||||||||||||||
| 257 | } | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | 1 | 42; | |||||||||||||||||||
| 260 | |||||||||||||||||||||