This file is indexed.

/usr/share/perl5/Debian/LicenseReconcile/CopyrightDatum.pm is in license-reconcile 0.14.

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
package Debian::LicenseReconcile::CopyrightDatum;

use 5.006;
use strict;
use warnings;
use Scalar::Util qw(blessed);
use Readonly;
use Set::IntSpan;
use Debian::LicenseReconcile::CopyrightDatum::Holder;
use Debian::LicenseReconcile::Errors;
use List::MoreUtils qw(part);
use Smart::Comments -ENV;

Readonly my $NL_RE => qr{
    \s*
    $
    \s*
}xms;

Readonly my $FILLER_RE => '[\-,\s\(\)]';

# We regard each line as a Set::IntSpan run list followed by free text.
Readonly my $LINE_RE => qr{
    \A                          # start of string
    (?:
        Copyright
        (?:\s+\([cC]\)\s*?)?
        [:\s]
    )?                          # Copyright string
    $FILLER_RE*                 # filler
    (                           # start of Set::IntSpan
        \d{4}                   # year
        (?:$FILLER_RE+\d{4})*   # more years
    )?                          # end of Set::IntSpan
    $FILLER_RE*                 # filler
    (.*?)                       # free text copyright holder
    (?:                         # All rights reserved
        \s*
        All\s+[Rr]ights\s+[Rr]eserved
        \.?
    )?
    \s*
    \z                          # end of string
}xms;

Readonly my $MAX_RELATIVE_WIDTH => 0.33;

sub new {
    my $class = shift;
    my $self = {};
    bless $self, $class;
    my $text = shift;
    if (ref $text eq 'ARRAY') {
        foreach my $line (@$text) {
            $self->_parse($line);
        }
    }    
    elsif ($text) {
        $self->_parse($text);
    }
    return $self;
}

sub _parse {
    my $self = shift;
    my $text = shift;
    foreach my $line (split $NL_RE, $text) {
        next if not $line;

        $line =~ s!,\s+(\d{4})\s+(\d{4}),\s+!, $1, $2, !g;

        my $match = ($line =~ $LINE_RE);
        ### assert: $match
        my $set_intspan = $1;
        my $copyright_holder = $2;
        $self->{$copyright_holder} = eval {
            Set::IntSpan->new($set_intspan)
        };
        if ($@) {
            my @err = split $NL_RE, $@;
            Debian::LicenseReconcile::Errors->push(
                test => 'Copyright parsing',
                msg => "Trying to parse $set_intspan: $err[0]",
            );
            $self->{$copyright_holder} = Set::IntSpan->new;
        }
    }
    return;
}
    
sub contains {
    my $self = shift;
    my $other = shift;
    my $msg_ref = shift;
    undef $msg_ref if not ref $msg_ref;
    return _msg($msg_ref, 'The other copyright data was undefined.')
        if not defined $other;
    my $other_class = blessed $other || '';
    if ($other_class ne 'Debian::LicenseReconcile::CopyrightDatum') {
        $other = Debian::LicenseReconcile::CopyrightDatum->new($other);
    }

    # 1.) Get lists of our and their copyright holders.
    # 2.) If we have less than theirs that is an easy fail.
    # 3.) Match off any that are exact matches and check those
    # 4.) Now create a mapping from Levenshtein distances to sets of pairs
    # of copyright holders. However if a holder is equidistant between
    # two oppisate holders then we immediately reject the whole
    # match as being ambiguous.
    # 5.) If we get this far then working from the shortest Levenshtein
    # distances up, we can pair off copyright holders and run the other
    # checks.
    my $our_data = $self->as_hash;
    my $their_data = $other->as_hash;
    my @their_keys = keys %$their_data;
    my $our_size = keys %$our_data;
    my $their_size = @their_keys;
    if ($our_size < $their_size) {
        my $our_list = join '|', keys %$our_data;
        my $their_list = join '|', keys %$their_data;
        return _msg($msg_ref, "$their_size cannot be fitted into $our_size: ($their_list) versus ($our_list)");
    }

    foreach my $key (@their_keys) {
        if (exists $our_data->{$key}) {
            my $our_years = delete $our_data->{$key};
            my $their_years = delete $their_data->{$key};
            if (not $their_years le $our_years) {
                return _msg($msg_ref,
                    "For copyright holder '$key' the years $their_years cannot be fitted into $our_years.");
            }
        }
    }

    my @pairs =
        sort {$a <=> $b}
        map {
            my $ours = $_;
            map {
                Debian::LicenseReconcile::CopyrightDatum::Holder->new(
                    theirs=>$_,
                    ours=>$ours
                )
            }
            keys %$their_data # note could be a subset of @their_keys
        }
        keys %$our_data;
    while(@pairs) {
        my $subject = $pairs[0];
        if ($subject->relative_width > $MAX_RELATIVE_WIDTH) {
            my $ours = $subject->ours;
            my $theirs = $subject->theirs;
            return _msg($msg_ref,
                "Trying to match '$theirs' against '$ours' but it does not look like a good match.");
        }
        my ($like_subject, $unlike_subject) = part {not $subject->touches($_)} @pairs;
        if ($subject->is_ambiguous($like_subject)) {
            my $friend = $like_subject->[1];
            my $subject_ours = $subject->ours;
            my $friend_ours = $friend->ours;
            my $subject_theirs = $subject->theirs;
            my $friend_theirs = $friend->theirs;
            if ($subject_ours eq $friend_ours) {
                return _msg($msg_ref,
                    "Was trying to match '$subject_theirs' to '$subject_ours', but '$friend_theirs' would match as well so giving up."); 
            }
            ### assert: $subject_theirs eq $friend_theirs
            return _msg($msg_ref,
                "Was trying to match '$subject_theirs' to '$subject_ours', but '$friend_ours' would be matched as well so giving up."); 
        }
        my $our_key = $subject->ours;
        my $their_key = $subject->theirs;
        my $our_years = delete $our_data->{$our_key};
        my $their_years = delete $their_data->{$their_key};
        if (not $their_years le $our_years) {
            return _msg($msg_ref,
                "For copyright holder '$their_key' (which looks like '$our_key') the years $their_years cannot be fitted into $our_years.");
        }
        @pairs = $unlike_subject ? @$unlike_subject : ();
    }

    return 1;
}

sub _msg {
    my $msg_ref = shift;
    my $text = shift;
    ### assert: $msg_ref
    $$msg_ref = $text;
    return 0;
}

sub copyright_holders {
    my $self = shift;
    return keys %$self;
}

sub years {
    my $self = shift;
    my $holder = shift;
    return if not exists $self->{$holder};
    return $self->{$holder};
}

sub as_hash {
    my $self = shift;
    my %hash = %$self;
    return \%hash;
}

=head1 NAME

Debian::LicenseReconcile::CopyrightDatum - copyright data as an object

=head1 VERSION

Version 0.14

=cut

our $VERSION = '0.14';

=head1 DESCRIPTION

This module conceives of copyright data as a mapping from strings
(the individual copyright holders) to sets of years.

Copyright data can be compared. Datum C<A> is contained in Datum C<B>
if for every key C<k> in C<A>, C<A{k}> is contained in C<B{l}>, where C<l> is the
key in C<B> that most closely matches C<k>. When matching strings they
are paired off in a 1-1 manner.

=head1 SYNOPSIS

    use Debian::LicenseReconcile::CopyrightDatum;

    my $copyright = Debian::LicenseReconcile::CopyrightDatum->new($text);

    my $explanation = "";
    if (not $copyright->contains($copyright2, \$explanation)) {
        warn $explanation;
    }

=head1 SUBROUTINES/METHODS

=head2 new

This constructor parses a copyright string.

=head2 contains

This method returns a boolean indicating whether the object contains the argument.
The method will respect the argument if it is a
L<Debian::LicenseReconcile::CopyrightDatum> and otherwise stringify and parse it.
It may also take an optional reference. If this is set on failing to
verify containment the reason found will be placed in that reference.

=head2 copyright_holders 

This method returns the list of copyright holders parsed from the original string.

=head2 years

Given an exactly matching copyright holder this returns the set of years
as an L<Set::IntSpan> object.

=head2 as_hash

Returns a hash reference of the objects data.

=head1 AUTHOR

Nicholas Bamber, C<< <nicholas at periapt.co.uk> >>

=head1 LICENSE AND COPYRIGHT

Copyright 2012, 2015, Nicholas Bamber C<< <nicholas at periapt.co.uk> >>.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.


=cut

1; # End of Debian::LicenseReconcile::FormatSpec