| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | Module::MetaInfo::ModList.pm - get meta information from the modlist | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This uses the 03modlist.data file from CPAN to get meta information | ||||||||||||||||||||||||||||
| 8 | about perl modules. | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 new(filename) | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | Creates an object and reads the modlist file if needed. At present | ||||||||||||||||||||||||||||
| 15 | the module list is read in for every ModList object created. This may | ||||||||||||||||||||||||||||
| 16 | change in future for greater efficiency, e.g. by doing it once and | ||||||||||||||||||||||||||||
| 17 | storing the result in a hash in the class. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | package Module::MetaInfo::ModList; | ||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use Symbol; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | sub _read_modlist { | ||||||||||||||||||||||||||
|
Subroutine
_read_modlist: called CC=11 SCAR=24.1
| |||||||||||||||||||||||||||||
| 28 | 5 | my $self=shift; | |||||||||||||||||||||||||||
| 29 | 5 | my $file=shift; | |||||||||||||||||||||||||||
| 30 | 5 | my $fh = Symbol::gensym(); | |||||||||||||||||||||||||||
| 31 | 5 | my $data; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | open $fh, "<$file"; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 5 | my $contents=""; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 125 | ▶ | m/^\s*\$cols/ and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 5 | $contents .=$_; | |||||||||||||||||||||||||||
| 40 | 5 | last; | |||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 5 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 107105 | $contents .=$_; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 5 | eval $contents; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 5 | $self->{array}=$data; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # # We hardwire the column into the code here. Argument is that since | ||||||||||||||||||||||||||||
| 51 | # # it's the first column it's unlikely to change, | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # $col=0; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | my $col; | |||||||||||||||||||||||||||
| 56 | 5 | my $primary = "modid"; | |||||||||||||||||||||||||||
| 57 | 5 | my %colhash=(); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 5 | ▶ | for (my $i=0;$i <= $#$cols; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 40 | $colhash{$cols->[$i]}=$i; | |||||||||||||||||||||||||||
| 61 | 40 | ▶ | $cols->[$i] eq $primary and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 5 | $col=$i; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 5 | $self->{colhash}=\%colhash; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 5 | ▶ | die "undefined column $primary" unless defined $col; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | my %hash; | |||||||||||||||||||||||||||
| 71 | 5 | foreach (@$data) { | |||||||||||||||||||||||||||
| 72 | 10705 | $hash{$_->[$col]} = $_; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | $self->{hash}=\%hash; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 5 | ▶ | die "Failed eval contents of modlist file: $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 5 | ▶ | die "\$data variable empty after modlist file" unless $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 5 | ▶ | die "\$data is not an aray ref" unless (ref $data) =~ m/ARRAY/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=20.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 5 | my $s = shift; | |||||||||||||||||||||||||||
| 85 | 5 | my $dist_name = shift; | |||||||||||||||||||||||||||
| 86 | 5 | my $mod_file_name = shift; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 5 | ▶ | croak "usage \$thing->new <distfilename> <modlist_filename>" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $mod_file_name or @_
MC/DC0%0/2
not $mod_file_name or @_
not $mod_file_name
@_
Truth table33%1/3
not(A) or B
A= not $mod_file_nameB= @_
| |||||||||||||||||||||||||||||
| 89 | if (not $mod_file_name) or @_; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 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
| |||||||||||||||||||||||||||||
| 92 | 5 | my $self={}; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 5 | my $name=$dist_name; | |||||||||||||||||||||||||||
| 96 | 5 | ▶ | die "dist file name can't end in /" if $name=~m,/$,; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 5 | $name =~ s,^.*/,,; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # checking the complete list teaches us that all module versions have | ||||||||||||||||||||||||||||
| 100 | # a number in them but they can have a letter at any point including | ||||||||||||||||||||||||||||
| 101 | # as the first character of the version... Which is not helpful. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 5 | ▶ | $name =~ s/-[^-][^0-9][^-]*(.tar.gz)?$// | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | or warn "lack of version in package name: $name"; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 5 | $name =~ s/-/::/g; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 5 | ▶ | croak "failed to get package name" unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 5 | $self->{name}=$name; | |||||||||||||||||||||||||||
| 111 | 5 | $self->{dist_name}=$dist_name; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 5 | bless $self, $class; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | $self->_read_modlist($mod_file_name); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 5 | return $self; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 7 | ▶ | sub _return_col { | ||||||||||||||||||||||||||
|
Subroutine
_return_col: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | 7 | my $self=shift; | |||||||||||||||||||||||||||
| 123 | 7 | my $col=shift; | |||||||||||||||||||||||||||
| 124 | 7 | return $self->{hash}->{$self->{name}}->[$self->{colhash}->{$col}]; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head2 development_stage() support_level() | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | these functions return the development stage / support level as | ||||||||||||||||||||||||||||
| 132 | defined in the perl modules list using the coding defined in the | ||||||||||||||||||||||||||||
| 133 | modules list. This is an interface which is almost certain to change. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | ▶ | sub development_stage { | ||||||||||||||||||||||||||
|
Subroutine
development_stage: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 2 | return shift->_return_col("statd"); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub support_level { | ||||||||||||||||||||||||||
|
Subroutine
support_level: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 2 | return shift->_return_col("stats"); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 description() summary() | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | these functions return the description from the modules list. This | ||||||||||||||||||||||||||||
| 148 | isn't really a very good description, but is better than nothing. As | ||||||||||||||||||||||||||||
| 149 | a summary though it's fine. | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 3 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 154 | #FIXME; add a slightly more verbose explanation that this is a perl module. | ||||||||||||||||||||||||||||
| 155 | 3 | return shift->_return_col("description"); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub summary { | ||||||||||||||||||||||||||
|
Subroutine
summary: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | 0 | return shift->_return_col("description"); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =head2 author() | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | This returns the pause userid of the author of the module. This can | ||||||||||||||||||||||||||||
| 165 | normally be converted into an email address by adding C<@cpan.org> at | ||||||||||||||||||||||||||||
| 166 | the end of it. Please don't put that on any web pages without using | ||||||||||||||||||||||||||||
| 167 | web trawler poison. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub author { | ||||||||||||||||||||||||||
|
Subroutine
author: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 0 | return shift->_return_col("userid"); | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 2 | 1; | |||||||||||||||||||||||||||