This file is indexed.

/usr/bin/perlver is in libperl-minimumversion-perl 1.38-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

package perlver;
$perlver::VERSION = '1.38';
=pod

=head1 NAME

perlver - The Perl Minimum Version Analyzer

=head1 SYNOPSIS

  adam@red:~$ perlver Perl-MinimumVersion
  Found directory '.'
  Searching for Perl files... found 3 file(s)
  Scanning lib/Perl/MinimumVersion.pm... done
  Scanning t/01_compile.t... done
  Scanning t/02_main.t... done

      ---------------------------------------------------------
    | file                       | explicit | syntax | external |
    | --------------------------------------------------------- |
    | lib/Perl/MinimumVersion.pm | 5.005    | ~      | n/a      |
    | t/01_compile.t             | ~        | ~      | n/a      |
    | t/02_main.t                | ~        | ~      | n/a      |
      ---------------------------------------------------------

  Minimum version of Perl required: ...

  adam@red:~$

=head1 DESCRIPTION

C<perlver> is a console script created to provide convenient access to the
functionality provided by L<Perl::MinimumVersion>.

--blame option shows code which requires this version of perl

The synopsis above pretty much covers all you need to know at this point.

=cut

use 5.005;
use strict;
use version                'qv';
use File::Spec             ();
use Getopt::Long           'GetOptions';
use Params::Util           '_INSTANCE';
use File::Find::Rule       ();
use File::Find::Rule::Perl ();
use Perl::MinimumVersion   'PMV';

# Define prototypes
sub verbose        ($);
sub message        ($);
sub error          (@);
sub format_version ($);
sub dist           ($);

use vars qw{$VERBOSE $BLAME $EXPLAIN};
BEGIN {

	# Configuration globals
	$VERBOSE = '';
	$BLAME   = '';
	$EXPLAIN = '';

	# Unbuffer output
	$| = 1;
}





#####################################################################
# Configuration

GetOptions(
	verbose => \$VERBOSE,
	blame   => \$BLAME,
	explain => \$EXPLAIN,
);

# Get the target
my $target = shift @ARGV;
unless ( $target ) {
	error("You did not provide a file or directory to check");
}

print "\n";
if ( $BLAME ) {
	blame($target);
} else {
	summary($target);
}

exit(0);





#####################################################################
# Regular Mode

sub summary {
	my $target = shift;
	my @files  = ();
	if ( -d $target ) {
		verbose "Found directory '$target'\n";
		verbose "Searching for Perl files... ";
		@files = find($target);
		verbose "found " . scalar(@files) . " file(s)\n";
	} elsif ( -f $target ) {
		verbose "Found file '$target'\n";
		@files = $target;
	} else {
		error "File or directory '$target' does not exist";
	}

	# Scan the files
	verbose "Processing files...\n";
	my @results  = ();
	my $file_len = 12 + List::Util::max map { length $_ } @files;
	foreach my $file ( @files ) {
		# Set up the results data
		verbose sprintf("%-${file_len}s", "Scanning $file...");
		my $result  = [ $file, undef, undef ];
		push @results, $result;

		# Load the document standalone first so we store the file name
		my $document = PPI::Document::File->new(
			$file,
			readonly => 1,
		);
		unless ( $document ) {
			verbose "[error]\n";
			next;
		}

		# Create the version checker
		my $pmv = PMV->new( $document );
		unless ( $pmv ) {
			verbose "[error]\n";
			next;
		}

		# Check the explicit version
		$result->[1] = $pmv->minimum_explicit_version;

		# Check the syntax version
		$result->[2] = $pmv->minimum_syntax_version;

		$result->[4] = $pmv->{syntax_check_failed} if exists $pmv->{syntax_check_failed};

		verbose "[ok]\n";
	}

	# Calculate the minimum explicit, syntax and total versions
	verbose "Compiling results...\n";
	my $pmv_explicit = PMV->_max( map { $_->[1] } @results   );
	my $pmv_syntax   = PMV->_max( map { $_->[2] } @results   );
	my $pmv_bug      = !! ($pmv_explicit and $pmv_syntax and $pmv_syntax > $pmv_explicit);
	my $pmv_total    = PMV->_max( $pmv_explicit, $pmv_syntax );

	# Generate the output values
	my @outputs = ( [ 'file', 'explicit', 'syntax', 'external' ] );
	foreach my $result ( @results ) {
		my $output = [];
		$output->[0] = $result->[0];
		$output->[1] = format_version($result->[1]);
		$output->[2] = format_version($result->[2]);
		# $output->[3] = format_version($result->[3]);
		$output->[3] = 'n/a';
		$output->[4] = $result->[4] || '' if ($EXPLAIN);
		push @outputs, $output;
	}

	# Complete the output preperation work
	$pmv_explicit     = format_version( $pmv_explicit );
	$pmv_syntax       = format_version( $pmv_syntax   );
	$pmv_total        = format_version( $pmv_total    );
	if ( $pmv_total eq '~' ) {
		$pmv_total = format_version( qv(5.004) ) . ' (default)';
	}
	my $len0          = List::Util::max map { length $_->[0] } @outputs;
	my $len1          = List::Util::max map { length $_->[1] } @outputs;
	my $len2          = List::Util::max map { length $_->[2] } @outputs;
	my $len3          = List::Util::max map { length $_->[3] } @outputs;
	my $len_all       = $len0 + $len1 + $len2 + $len3 + 9;
	my $len_totals    = $len1 + $len2 + $len3 + 6;
	my $line_format   = " | %-${len0}s | %-${len1}s | %-${len2}s | %-${len3}s |\n";
	if ($EXPLAIN) {
	  chomp($line_format);
	  $line_format.="  (%s)\n";
	}
	my $spacer        = '-' x $len_all;
	my $error_message = "ERROR DETECTED : ACTUAL DEPENDENCY HIGHER THAN SPECIFIED";
	my $error_length  = length $error_message;
	if ( $error_length > $len_all ) {
		my $diff = $error_length - $len_all;
		$len_all += $diff;
		$len0    += $diff;
	}

	# Prepare formatting parts
	my $divider = " | $spacer |\n";
	my $capline = "   $spacer  \n";
	my $rowline = " | %-${len_all}s |\n";

	# Print the results
	print "\n";
	print $capline;
	printf( $line_format, @{shift(@outputs)} );
	print $divider;
	foreach my $result ( @outputs ) {
		printf( $line_format, @$result );
	}
	print $divider;
	printf( $rowline, "Minimum explicit version : $pmv_explicit" );
	printf( $rowline, "Minimum syntax version   : $pmv_syntax"   );
	printf( $rowline, "Minimum version of perl  : $pmv_total"    );
	if ( $pmv_bug ) {
		print $divider;
		printf( $rowline, "ERROR   : ACTUAL DEPENDENCY HIGHER THAN SPECIFIED" );
		printf( $rowline, "DETAILS : perlver --blame $target" );
	}
	print $capline;
	print "\n";
}

sub blame {
	my $target = shift;
	my @files  = ();
	if ( -d $target ) {
		verbose "Found directory '$target'\n";
		verbose "Searching for Perl files... ";
		@files = find($target);
		verbose "found " . scalar(@files) . " file(s)\n";
	} elsif ( -f $target ) {
		verbose "Found file '$target'\n";
		@files = $target;
	} else {
		error "File or directory '$target' does not exist";
	}

	# Scan the files
	verbose "Processing files...\n";
	my $maximum  = undef;
	my $blame    = undef;
	my $file_len = 12 + List::Util::max map { length $_ } @files;
	my $max      = undef;
	my $maxpmv   = undef;
	foreach my $file ( @files ) {
		# Set up the results data
		verbose sprintf("%-${file_len}s", "Scanning $file...");

		# Load the document standalone first so we store the file name
		my $document = PPI::Document::File->new(
			$file,
			readonly => 1,
		);
		unless ( $document ) {
			verbose "[error]\n";
			next;
		}

		# Create the version checker
		my $pmv = PMV->new( $document );
		unless ( $pmv ) {
			verbose "[error]\n";
			next;
		}

		# Check the syntax version
		my $reason = $pmv->minimum_syntax_reason( $max ? $max->version : undef );
		if ( $reason ) {
			verbose $reason->version . "\n";
		} else {
			verbose "~\n";
			next;
		}

		# Handle the first successful case
		if ( ! $max or $reason->version > $max->version ) {
			$max    = $reason;
			$maxpmv = $pmv;
			next;
		}
	}

	# Anything?
	unless ( $max ) {
		print "Nothing obvious to blame\n";
		exit(0);
	}

	# Index and prepare
	my $element  = $max->element or die "Reason element unknown";
	my $document = $element->top or die "Reason document unknown";
	$document->index_locations;

	# Generate the location message
	my $file    = $document->filename;
	my $line    = $element->line_number;
	my $char    = $element->column_number;
	my $content = $element->content;
	my $rule    = $max->rule;
	my $version = $max->version;
	print " ------------------------------------------------------------\n";
	print " File    : $file\n";
	print " Line    : $line\n";
	print " Char    : $char\n";
	print " Rule    : $rule\n";
	print " Version : $version\n";
	print " ------------------------------------------------------------\n";
	print " $content\n";
	print " ------------------------------------------------------------\n";
}

sub find {
	my $dir   = shift;
	my $perl  = File::Find::Rule->perl_file;
	my $build = File::Find::Rule->name('blib', '_build')->directory;
	return dist($dir)
		? File::Find::Rule->any(
				$build->prune->discard,
				$perl,
		  )->in( $dir )
		: $perl->in( $dir );
}





#####################################################################
# Support Functions

sub verbose ($) {
	return 1 unless $VERBOSE;
	print ' ' . $_[0];
}

sub message ($) {
	print ' ' . $_[0];
}

sub error (@) {
	print ' ' . join '', map { "$_\n" } ('', @_, '');
	exit(255);
}

sub format_version ($) {
	my $version = shift;
	if ( _INSTANCE($version, 'Perl::MinimumVersion::Reason') ) {
		$version = $version->version->normal;
	} elsif ( _INSTANCE($version, 'version') ) {
		return $version->normal;
	} elsif ( $version ) {
		return "$version";
	} elsif ( defined $version ) {
		return '~';
	} else {
		return 'undef';
	}
}

sub format_reason ($) {
	my $reason = shift;

	# Index the document of the worse offender
	my $element  = $reason->element;
	my $document = $element->top;
	$document->index_locations;

	$DB::single = 1;

	1;
}

sub dist ($) {
	my $dir = shift;
	if ( -f File::Spec->catfile($dir, 'Makefile.PL') ) {
		return 1;
	}
	if ( -f File::Spec->catfile($dir, 'Build.PL') ) {
		return 1;
	}
	return '';
}

=pod

=head1 TO DO

- Add PPI::Cache integration

- Add PPI::Metrics integration (once it exists)

- Add some sort of parseable output

=head1 SUPPORT

All bugs should be filed via the bug tracker at

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-MinimumVersion>

For other issues, or commercial enhancement and support, contact the author

=head1 AUTHORS

Adam Kennedy <adamk@cpan.org>

=head1 SEE ALSO

L<PPI>, L<Perl::MinimumVersion>

=head1 COPYRIGHT

Copyright 2005 - 2012 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut