| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::ThisDist; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
338321
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
55
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
99
|
|
|
5
|
1
|
|
|
1
|
|
1510
|
use Log::ger; |
|
|
1
|
|
|
|
|
41
|
|
|
|
1
|
|
|
|
|
4
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
175
|
use Exporter qw(import); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
26
|
|
|
8
|
1
|
|
|
1
|
|
508
|
use File::chdir; |
|
|
1
|
|
|
|
|
2553
|
|
|
|
1
|
|
|
|
|
1887
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
|
11
|
|
|
|
|
|
|
our $DATE = '2024-12-21'; # DATE |
|
12
|
|
|
|
|
|
|
our $DIST = 'App-ThisDist'; # DIST |
|
13
|
|
|
|
|
|
|
our $VERSION = '0.024'; # VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(this_dist this_mod); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub this_dist { |
|
18
|
0
|
|
|
0
|
1
|
|
require File::Slurper; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my ($dir, $extract_version, $detail) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
if (defined $dir) { |
|
23
|
0
|
|
|
|
|
|
log_debug "chdir to $dir ..."; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
local $CWD = $dir if defined $dir; |
|
27
|
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
unless (defined $dir) { |
|
29
|
0
|
|
|
|
|
|
require Cwd; |
|
30
|
0
|
|
|
|
|
|
$dir = Cwd::getcwd(); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
(my $dir_basename = $dir) =~ s!.+[/\\]!!; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my ($distname, $distver, $detailinfo); |
|
36
|
0
|
|
|
|
|
|
$detailinfo = {}; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
GUESS: { |
|
39
|
0
|
|
|
|
|
|
FROM_DISTMETA_2: { |
|
40
|
0
|
|
|
|
|
|
for my $file ("MYMETA.json", "META.json") { |
|
|
0
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
next unless -f $file; |
|
42
|
0
|
|
|
|
|
|
log_debug "Found distribution metadata $file"; |
|
43
|
0
|
|
|
|
|
|
require JSON::PP; |
|
44
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text($file); |
|
45
|
0
|
|
|
|
|
|
my $meta = JSON::PP::decode_json($content); |
|
46
|
0
|
0
|
0
|
|
|
|
if ($meta && ref $meta eq 'HASH' && defined $meta->{name}) { |
|
|
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$distname = $meta->{name}; |
|
48
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from distribution metadata $file"; |
|
49
|
0
|
|
|
|
|
|
$detailinfo->{source} = 'dist meta v2'; |
|
50
|
0
|
|
|
|
|
|
$detailinfo->{dist_meta_file} = $file; |
|
51
|
0
|
0
|
|
|
|
|
if (defined $meta->{version}) { |
|
52
|
0
|
|
|
|
|
|
$distver = $meta->{version}; |
|
53
|
0
|
|
|
|
|
|
log_debug "Got distver=$distver from distribution metadata $file"; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
0
|
|
|
|
|
|
last GUESS; |
|
56
|
|
|
|
|
|
|
} else { |
|
57
|
0
|
|
|
|
|
|
last; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
FROM_DISTMETA_1_1: { |
|
63
|
0
|
|
|
|
|
|
for my $file ("MYMETA.yml", "META.yml") { |
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
next unless -f $file; |
|
65
|
0
|
|
|
|
|
|
log_debug "Found distribution metadata $file"; |
|
66
|
0
|
|
|
|
|
|
require YAML::XS; |
|
67
|
0
|
|
|
|
|
|
my $meta = YAML::XS::LoadFile($file); |
|
68
|
0
|
0
|
0
|
|
|
|
if ($meta && ref $meta eq 'HASH' && defined $meta->{name}) { |
|
|
|
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$distname = $meta->{name}; |
|
70
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from distribution metadata $file"; |
|
71
|
0
|
|
|
|
|
|
$detailinfo->{source} = 'dist meta v1.1'; |
|
72
|
0
|
|
|
|
|
|
$detailinfo->{dist_meta_file} = $file; |
|
73
|
0
|
0
|
|
|
|
|
if (defined $meta->{version}) { |
|
74
|
0
|
|
|
|
|
|
$distver = $meta->{version}; |
|
75
|
0
|
|
|
|
|
|
log_debug "Got distver=$distver from distribution metadata $file"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
0
|
|
|
|
|
|
last GUESS; |
|
78
|
|
|
|
|
|
|
} else { |
|
79
|
0
|
|
|
|
|
|
last; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
FROM_DIST_INI: { |
|
85
|
0
|
0
|
|
|
|
|
last unless -f "dist.ini"; |
|
|
0
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
log_debug "Found dist.ini"; |
|
87
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text("dist.ini"); |
|
88
|
0
|
|
|
|
|
|
while ($content =~ /^\s*name\s*=\s*(.+)/mg) { |
|
89
|
0
|
|
|
|
|
|
$distname = $1; |
|
90
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from dist.ini"; |
|
91
|
0
|
|
|
|
|
|
$detailinfo->{source} = "dist.ini"; |
|
92
|
0
|
0
|
|
|
|
|
if ($content =~ /^version\s*=\s*(.+)/m) { |
|
93
|
0
|
|
|
|
|
|
$distver = $1; |
|
94
|
0
|
|
|
|
|
|
log_debug "Got distver=$distver from dist.ini"; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
0
|
|
|
|
|
|
last GUESS; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
FROM_MAKEFILE_PL: { |
|
101
|
0
|
0
|
|
|
|
|
last unless -f "Makefile.PL"; |
|
|
0
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
log_debug "Found Makefile.PL"; |
|
103
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text("Makefile.PL"); |
|
104
|
0
|
0
|
|
|
|
|
unless ($content =~ /use ExtUtils::MakeMaker/) { |
|
105
|
0
|
|
|
|
|
|
log_debug "Makefile.PL doesn't seem to use ExtUtils::MakeMaker, skipped"; |
|
106
|
0
|
|
|
|
|
|
last; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
0
|
0
|
|
|
|
|
unless ($content =~ /["']DISTNAME["']\s*=>\s*["'](.+?)["']/) { |
|
109
|
0
|
|
|
|
|
|
log_debug "Couldn't extract value of DISTNAME from Makefile.PL, skipped"; |
|
110
|
0
|
|
|
|
|
|
last; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
0
|
|
|
|
|
|
$distname = $1; |
|
113
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from Makefile.PL"; |
|
114
|
0
|
|
|
|
|
|
$detailinfo->{source} = "Makefile.PL"; |
|
115
|
0
|
0
|
|
|
|
|
if ($content =~ /["']VERSION["']\s*=>\s*["'](.+?)["']/) { |
|
116
|
0
|
|
|
|
|
|
$distver = $1; |
|
117
|
0
|
|
|
|
|
|
log_debug "Got distver=$distver from Makefile.PL"; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
0
|
|
|
|
|
|
last GUESS; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
FROM_MAKEFILE: { |
|
123
|
0
|
0
|
|
|
|
|
last unless -f "Makefile"; |
|
|
0
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
log_debug "Found Makefile"; |
|
125
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text("Makefile"); |
|
126
|
0
|
0
|
|
|
|
|
unless ($content =~ /by MakeMaker/) { |
|
127
|
0
|
|
|
|
|
|
log_debug "Makefile doesn't seem to be generated from MakeMaker.PL, skipped"; |
|
128
|
0
|
|
|
|
|
|
last; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
0
|
0
|
|
|
|
|
unless ($content =~ /^DISTNAME\s*=\s*(.+)/m) { |
|
131
|
0
|
|
|
|
|
|
log_debug "Couldn't extract value of DISTNAME from Makefile, skipped"; |
|
132
|
0
|
|
|
|
|
|
last; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
0
|
|
|
|
|
|
$distname = $1; |
|
135
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from Makefile"; |
|
136
|
0
|
|
|
|
|
|
$detailinfo->{source} = "Makefile"; |
|
137
|
0
|
0
|
|
|
|
|
if ($content =~ /^VERSION\s*=\s*(.+)/m) { |
|
138
|
0
|
|
|
|
|
|
$distver = $1; |
|
139
|
0
|
|
|
|
|
|
log_debug "Got distver=$distver from Makefile"; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
0
|
|
|
|
|
|
last GUESS; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
FROM_BUILD_PL: { |
|
145
|
0
|
0
|
|
|
|
|
last unless -f "Build.PL"; |
|
|
0
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
log_debug "Found Build.PL"; |
|
147
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text("Build.PL"); |
|
148
|
0
|
0
|
|
|
|
|
unless ($content =~ /use Module::Build/) { |
|
149
|
0
|
|
|
|
|
|
log_debug "Build.PL doesn't seem to use Module::Build, skipped"; |
|
150
|
0
|
|
|
|
|
|
last; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
0
|
0
|
|
|
|
|
unless ($content =~ /module_name\s*=>\s*["'](.+?)["']/s) { |
|
153
|
0
|
|
|
|
|
|
log_debug "Couldn't extract value of module_name from Build.PL, skipped"; |
|
154
|
0
|
|
|
|
|
|
last; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
0
|
|
|
|
|
|
$distname = $1; $distname =~ s/::/-/g; |
|
|
0
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
log_debug "Got distname=$distname from Build.PL"; |
|
158
|
0
|
|
|
|
|
|
$detailinfo->{source} = "Build.PL"; |
|
159
|
|
|
|
|
|
|
# XXX extract version? |
|
160
|
0
|
|
|
|
|
|
last GUESS; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# note: Build script does not contain dist name |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
FROM_GIT_CONFIG: { |
|
166
|
0
|
|
|
|
|
|
last; # currently disabled |
|
|
0
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
last unless -f ".git/config"; |
|
168
|
0
|
|
|
|
|
|
log_debug "Found .git/config"; |
|
169
|
0
|
|
|
|
|
|
my $content = File::Slurper::read_text(".git/config"); |
|
170
|
0
|
|
|
|
|
|
while ($content =~ /^\s*url\s*=\s*(.+)/mg) { |
|
171
|
0
|
|
|
|
|
|
my $url = $1; |
|
172
|
0
|
|
|
|
|
|
log_debug "Found URL '$url' in git config"; |
|
173
|
0
|
|
|
|
|
|
require CPAN::Dist::FromURL; |
|
174
|
0
|
|
|
|
|
|
my $res = CPAN::Dist::FromURL::extract_cpan_dist_from_url($url); |
|
175
|
0
|
0
|
|
|
|
|
if (defined $distname) { |
|
176
|
0
|
|
|
|
|
|
log_debug "Guessed distname=$distname from .git/config URL '$url'"; |
|
177
|
0
|
|
|
|
|
|
$detailinfo->{source} = "git config"; |
|
178
|
|
|
|
|
|
|
# XXX extract version? |
|
179
|
0
|
|
|
|
|
|
last GUESS; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__DISABLED__FROM_REPO_NAME: { |
|
185
|
0
|
|
|
|
|
|
last; # currently disabled |
|
|
0
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
log_debug "Using CPAN::Dist::FromRepoName to guess from dir name ..."; |
|
187
|
0
|
|
|
|
|
|
require CPAN::Dist::FromRepoName; |
|
188
|
0
|
|
|
|
|
|
my $res = CPAN::Dist::FromRepoName::extract_cpan_dist_from_repo_name($dir_basename); |
|
189
|
0
|
0
|
|
|
|
|
if (defined $res) { |
|
190
|
0
|
|
|
|
|
|
$distname = $res; |
|
191
|
0
|
|
|
|
|
|
log_debug "Guessed distname=$distname from repo name '$dir_basename'"; |
|
192
|
0
|
|
|
|
|
|
$detailinfo->{source} = "repo name"; |
|
193
|
|
|
|
|
|
|
# XXX extract version? |
|
194
|
0
|
|
|
|
|
|
last GUESS; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
FROM_ARCHIVE: { |
|
199
|
0
|
|
|
|
|
|
require Filename::Type::Perl::Release; |
|
|
0
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# if there is a single archive in the directory which looks like a |
|
201
|
|
|
|
|
|
|
# perl release, use that. |
|
202
|
0
|
|
|
|
|
|
my @files = grep { -f } glob "*"; |
|
|
0
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
my ($distfile, $dist, $ver); |
|
204
|
0
|
|
|
|
|
|
for my $file (@files) { |
|
205
|
0
|
|
|
|
|
|
my $res = Filename::Type::Perl::Release::check_perl_release_filename(filename=>$file); |
|
206
|
0
|
0
|
|
|
|
|
next unless $res; |
|
207
|
0
|
0
|
|
|
|
|
last FROM_ARCHIVE if defined $dist; |
|
208
|
0
|
|
|
|
|
|
$dist = $res->{distribution}; |
|
209
|
0
|
|
|
|
|
|
$ver = $res->{version}; |
|
210
|
0
|
|
|
|
|
|
$distfile = $file; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
0
|
0
|
|
|
|
|
last unless defined $dist; |
|
213
|
0
|
|
|
|
|
|
$distname = $dist; |
|
214
|
0
|
|
|
|
|
|
$distver = $ver; |
|
215
|
0
|
|
|
|
|
|
log_debug "Guessed distname=$distname from a single perl archive file in the directory ($distfile)"; |
|
216
|
0
|
|
|
|
|
|
$detailinfo->{source} = "archive"; |
|
217
|
0
|
|
|
|
|
|
$detailinfo->{archive_file} = $distfile; |
|
218
|
0
|
|
|
|
|
|
last GUESS; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
log_debug "Can't guess distribution, giving up"; |
|
222
|
|
|
|
|
|
|
} # GUESS |
|
223
|
|
|
|
|
|
|
|
|
224
|
0
|
0
|
|
|
|
|
if ($detail) { |
|
225
|
0
|
|
|
|
|
|
$detailinfo->{dist} = $distname; |
|
226
|
0
|
|
|
|
|
|
$detailinfo->{dist_version} = $distver; |
|
227
|
0
|
|
|
|
|
|
$detailinfo; |
|
228
|
|
|
|
|
|
|
} else { |
|
229
|
0
|
0
|
|
|
|
|
return unless defined $distname; |
|
230
|
0
|
0
|
|
|
|
|
$extract_version ? "$distname ".(defined $distver ? $distver : "?") : $distname; |
|
|
|
0
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
sub this_mod { |
|
235
|
0
|
|
|
0
|
1
|
|
my $res = this_dist(@_); |
|
236
|
0
|
0
|
|
|
|
|
return $res unless defined $res; |
|
237
|
0
|
0
|
|
|
|
|
if (ref $res) { |
|
238
|
0
|
0
|
0
|
|
|
|
return $res unless $res->{dist} && $res->{dist} =~ /\S/; |
|
239
|
0
|
|
|
|
|
|
($res->{module} = $res->{dist}) =~ s/-/::/g; |
|
240
|
|
|
|
|
|
|
} else { |
|
241
|
0
|
0
|
|
|
|
|
return $res unless $res =~ /\S/; |
|
242
|
0
|
|
|
|
|
|
$res =~ s/-/::/g; |
|
243
|
|
|
|
|
|
|
} |
|
244
|
0
|
|
|
|
|
|
$res; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
1; |
|
248
|
|
|
|
|
|
|
# ABSTRACT: Print Perl {distribution,module,author,...} associated with current directory |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
__END__ |