This file is indexed.

/usr/share/perl5/Test/CheckChanges.pm is in libtest-checkchanges-perl 0.14-2.

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

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
package Test::CheckChanges;
use strict;
use warnings;

use Cwd;
use Carp;
use File::Spec;
use File::Basename;
use File::Glob "bsd_glob";
use Test::Builder;

our $test      = Test::Builder->new();

=head1 NAME

Test::CheckChanges - Check that the Changes file matches the distribution.

=head1 VERSION

Version 0.14

=cut

our $VERSION = '0.14';

=head1 SYNOPSIS

 use Test::CheckChanges;
 ok_changes();

You can make the test optional with 

 use Test::More;
 eval { require Test::CheckChanges };

 if ($@) {
     plan skip_all => 'Test::CheckChanges required for testing the Changes file';
 }
 ok_changes();

=head1 DESCRIPTION

This module checks that you I<Changes> file has an entry for the current version 
of the B<Module> being tested.

The version information for the distribution being tested is taken out
of the Build data, or if that is not found, out of the Makefile.

It then attempts to open, in order, a file with the name I<Changes> or I<CHANGES>.

The I<Changes> file is then parsed for version numbers.  If one and only one of the
version numbers matches the test passes.  Otherwise the test fails.

A message with the current version is printed if the test passes, otherwise
dialog messages are printed to help explain the failure.

The I<examples> directory contains examples of the different formats of
I<Changes> files that are recognized.

=cut

our $order = '';
our @change_files = qw (Changes CHANGES);
our $changes_regex = qr/(Changes|CHANGES)$/;
our $glob = "C[Hh][Aa][Nn][Gg][Ee][Ss]";

sub import {
    my ($self, %plan) = @_;
    my $caller = caller;

    if (defined $plan{order}) {
       $order = $plan{order};
       delete $plan{order};
    }

    for my $func ( qw( ok_changes ) ) {
        no strict 'refs';	## no critic
        *{$caller."::".$func} = \&$func;
    }

    $test->exported_to($caller);
    $test->plan(%plan);
    return;
}

=head1 FUNCTIONS

All functions listed below are exported to the calling namespace.

=head2 ok_changes( )

=over

The ok_changes method takes no arguments and returns no value.

=back

=cut
 
our @not_found;

sub ok_changes
{
    my %p;
    %p = @_ if @_ % 2 == 0;
    my $version;
    my $msg = 'Unknown Error';
    my $_base = delete $p{base} || '';

    die "ok_changes takes no arguments" if keys %p || @_ % 2 == 1;

    my $base = Cwd::realpath(File::Spec->catdir(dirname($0), '..', $_base));

    my $home     = $base;
    my @diag = ();

    my $makefile = File::Spec->catdir($base, 'Makefile');
    my $build = File::Spec->catdir($home, '_build', 'build_params');

    my $extra_text;

    if ($build && -r $build) {
        require Module::Build::Version;
        open(my $in, '<', $build);
        my $data = join '', <$in>;
        close($in);
        my $temp = eval $data;		## no critic
        $version = $temp->[2]{dist_version};
        $extra_text = "Build";
    } elsif ($makefile && -r $makefile) {
        open(my $in, '<', $makefile) or die "Could not open $makefile";
        while (<$in>) {
            chomp;
            if (/^VERSION\s*=\s*(.*)\s*/) {
                $version = $1;
                $extra_text = "Makefile";
                last;
            }
        }
        close($in) or die "Could not close $makefile";
    }
    if ($version) {
        $msg = "CheckChages $version " . $extra_text;
    } else {
        push(@diag, "No way to determine version");
        $msg = "No Build or Makefile found";
    }

    my $ok = 0;

    my $mixed = 0;
    my $found = 0;
    my $parsed = '';
    @not_found = ();

    # glob for the changes file and then filter if needed
    # this is sorted here so the filesystem is not in control of 
    #  the order of the files.
    
    my $glob_path = File::Spec->catdir($home, $glob);
    my @change_list = sort { $b cmp $a } grep({ m|$changes_regex|} bsd_glob($glob_path));

    my $change_file = $change_list[0];

    if (@change_list > 1) {
        for (@change_list) {
            s|^$home/||;
        }
        push(@diag, qq/Multiple Changes files found (/ .
        join(', ', map({'"' . $_ . '"'} @change_list)) .
        qq/) using "$change_list[0]"./);
    }

    if ($change_file and $version) {
        open(my $in, '<', $change_file) or die "Could not open ($change_file) File";
        my $type = 0;
        while (<$in>) {
            chomp;
            if (/^(\d|v\d)/) {
# Common
                my ($cvers, $date) = split(/\s+/, $_, 2);
                    $mixed++ if $type and $type != 1;
                    $type = 1;
#                    if ($date =~ /- version ([\d.]+)$/) {
#                        $cvers = $1;
#                    }
                    if ($version eq $cvers) {
                        $found = $_;
                        last;
                    } else {
                        push(@not_found, "$cvers");
                    }
            } elsif (/^\s+version: ([\d.]+)$/) {
# YAML
                $mixed++ if $type and $type != 2;
                $type = 2;
                if ($version eq $1) {
                    $found = $_;
                    last;
                } else {
                    push(@not_found, "$1");
                }
            } elsif (/^\* (v?[\d._]+)$/) {
# Apocal
                $mixed++ if $type and $type != 3;
                $type = 3;
                if ($version eq $1) {
                    $found = $_;
                    last;
                } else {
                    push(@not_found, "$1");
                }
            } elsif (/^Version (v?[\d._]+)($|[:,[:space:]])/) {
# Plain "Version N"
                $mixed++ if $type and $type != 4;
                $type = 4;
                if ($version eq $1) {
                    $found = $_;
                    last;
                } else {
                    push(@not_found, "$1");
                }
            }
        }
        close($in) or die "Could not close ($change_file) file";
        if ($found) {
            $ok = 1;
        } else {
            $ok = 0;
            $msg .= " Not Found.";
            if (@not_found) {
                push(@diag, qq(expecting version $version, found versions: ). join(', ', @not_found));
            } else {
                push(@diag, qq(expecting version $version, But no versions where found in the Changes file.));
            }
        }
    } 
    if (!$change_file) {
        push(@diag, q(No 'Changes' file found));
    }

    $test->ok($ok, $msg);
    for my $diag (@diag) {
        $test->diag($diag);
    }
    return;
}

END {
    if (!defined $test->has_plan()) {
	$test->done_testing(1);
    }
}

1;

=head1 CHANGES FILE FORMAT

Currently this package parses 4 different types of C<Changes> files.
The first is the common, free style, C<Changes> file where the version
is first item on an unindented line:

 0.01  Fri May  2 15:56:25 EDT 2008
       - more info  

The second type of file parsed is the L<Module::Changes::YAML> format changes file.

The third type of file parsed has the version number proceeded by an * (asterisk).

 Revision history for Perl extension Foo::Bar

 * 1.00

 Is this a bug or a feature

The fourth type of file parsed starts the line with the word Version
followed by the version number.

 Version 6.00  17.02.2008
  + Oops. Fixed version number. '5.10' is less than '5.9'. I thought
    CPAN would handle this but apparently not..

There are examples of these Changes file in the I<examples> directory.

Create an RT if you need a different format file supported.  If it is not horrid, I will add it.

The Debian style C<Changes> file will likely be the first new format added.

=head1 BUGS

Please open an RT if you find a bug.

L<http://rt.cpan.org/Public/Dist/Display.html?Name=Test-CheckChanges>

=head1 AUTHOR

"G. Allen Morris III" <gam3@gam3.net>

=head1 COPYRIGHT & LICENSE

Copyright (C) 2008-2010 G. Allen Morris III, all rights reserved.

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

=cut