This file is indexed.

/usr/share/perl5/Prophet/ChangeSet.pm is in libprophet-perl 0.750-1.

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
package Prophet::ChangeSet;
use Any::Moose;
use Prophet::Change;
use Params::Validate;
use Digest::SHA qw/sha1_hex/;
use JSON;

has creator => (
    is  => 'rw',
    isa => 'Str|Undef',
);

has created => (
    is      => 'rw',
    isa     => 'Str|Undef',
    default => sub {
        my ($sec, $min, $hour, $day, $month, $year) = gmtime;
        $year += 1900;
        $month++;
        return sprintf '%04d-%02d-%02d %02d:%02d:%02d',
            $year, $month, $day,
            $hour, $min, $sec;
    },
);

has source_uuid => (
    is  => 'rw',
    isa => 'Str|Undef',
);

has sequence_no => (
    is  => 'rw',
    isa => 'Int|Undef',
);

has original_source_uuid => (
    is  => 'rw',
    isa => 'Str',
);

has original_sequence_no => (
    is  => 'rw',
    isa => 'Int|Undef',
);

has is_nullification => (
    is  => 'rw',
    isa => 'Bool',
);

has is_resolution => (
    is  => 'rw',
    isa => 'Bool',
);

has changes => (
    is         => 'rw',
    isa        => 'ArrayRef',
    auto_deref => 1,
    default    => sub { [] },
);

has sha1 => ( 
    is => 'rw',
    isa => 'Maybe[Str]'
    );

sub has_changes { scalar @{ $_[0]->changes } }
sub _add_change {
    my $self = shift;
    push @{ $self->changes }, @_;
}

=head1 NAME

Prophet::ChangeSet

=head1 DESCRIPTION

This class represents a single, atomic Prophet database update. It tracks some
metadata about the changeset itself and contains a list of L<Prophet::Change>
entries which describe the actual records created, updated and deleted.

=head1 METHODS

=head2 new

Instantiate a new, empty L<Prophet::ChangeSet> object.

=head2 creator

A string representing who created this changeset.

=head2 created

A string representing the ISO 8601 date and time when this changeset
was created (UTC).

=head2 sequence_no

The changeset's sequence number (in subversion terms, revision #) on the
replica sending us the changeset.

=head2 source_uuid

The uuid of the replica sending us the change.

=head2 original_source_uuid

The uuid of the replica where the change was authored.

=head2 original_sequence_no

The changeset's sequence number (in subversion terms, revision #) on the
replica where the change was originally created.

=head2 is_nullification

A boolean value specifying whether this is a nullification changeset or not.

=head2 is_resolution

A boolean value specifying whether this is a conflict resolution changeset
or not.

=head2 changes

Returns an array of all the changes in the current changeset.

=head2 has_changes

Returns true if this changeset has any changes.

=head2 add_change { change => L<Prophet::Change> }

Adds a new change to this changeset.

=cut

sub add_change {
    my $self = shift;
    my %args = validate( @_, { change => { isa => 'Prophet::Change' } } );
    $self->_add_change($args{change});

}

our @SERIALIZE_PROPS
    = (qw(creator created sequence_no source_uuid original_source_uuid original_sequence_no is_nullification is_resolution));

=head2 as_hash

Returns a reference to a representation of this changeset as a hash, containing
all the properties in the package variable C<@SERIALIZE_PROPS>, as well as a
C<changes> key containing hash representations of each change in the changeset,
keyed on UUID.

=cut

sub as_hash {
    my $self = shift;
    my $as_hash = { map { $_ => $self->$_() } @SERIALIZE_PROPS };

    for my $change ( $self->changes ) {
        $as_hash->{changes}->{ $change->record_uuid } = $change->as_hash;
    }

    return $as_hash;
}

=head2 new_from_hashref HASHREF

Takes a reference to a hash representation of a changeset (such as is
returned by L</as_hash> or serialized json) and returns a new
Prophet::ChangeSet representation of it.

Should be invoked as a class method, not an object method.

For example:
C<Prophet::ChangeSet-E<gt>new_from_hashref($ref_to_changeset_hash)>

=cut

sub new_from_hashref {
    my $class   = shift;
    my $hashref = shift;
    my $self    = $class->new( { map { $_ => $hashref->{$_} } @SERIALIZE_PROPS } );

    for my $change ( keys %{ $hashref->{changes} } ) {
        $self->add_change( change => Prophet::Change->new_from_hashref( $change => $hashref->{changes}->{$change} ) );
    }
    return $self;
}

=head2 as_string ARGS

Returns a single string representing the changes in this changeset.

If C<$args{header_callback}> is defined, the string returned from passing
C<$self> to the callback is prepended to the changeset string before it is
returned (instead of L</description_as_string>).

If C<$args{skip_empty}> is defined, an empty string is returned if the
changeset contains no changes.

The argument C<change_filter> can be used to filter certain changes from
the string representation; the function is passed a change and should return
false if that change should be skipped.

The C<change_header> argument, if present, is passed to
C<$change-E<gt>to_string> when individual changes are converted to strings.

=cut

sub as_string {
    my $self = shift;
    my %args = validate(
        @_,
        {   change_filter => 0,
            change_header => 0,
            change_formatter => undef,
            header_callback => 0,
            skip_empty => 0
        }
    );

    my $body = '';
    
    for my $change ( $self->changes ) {
        next if $args{change_filter} && !$args{change_filter}->($change);
        if ($args{change_formatter} ) {
            $body .= $args{change_formatter}->(change => $change, header_callback => $args{change_header});
        } else {
        $body .= $change->as_string( header_callback => $args{change_header} ) || next;
        $body .= "\n";
        }
    }

    return '' if !$body && $args{'skip_empty'};

    my $header  = $args{header_callback} ? $args{header_callback}->($self) :  $self->description_as_string;
    my $out  = $header .$body;
    return $out;
}

=head2 description_as_string

Returns a string representing a description of this changeset.

=cut

sub description_as_string {
    my $self = shift;
     sprintf " %s at %s\t\(%d@%s)\n",
        ( $self->creator || '(unknown)' ),
        $self->created,
        $self->original_sequence_no,
        $self->original_source_uuid;
    }

sub created_as_rfc3339 {
    my $self = shift;
    my $c = $self->created;
    $c =~ s/ /T/;
    return $c."Z";
}

sub calculate_sha1 {
    my $self = shift;
    return sha1_hex($self->canonical_json_representation);
}

sub canonical_json_representation {
my $self = shift;
    my $hash_changeset = $self->as_hash;
    # These two things should never actually get stored
     delete $hash_changeset->{'sequence_no'};
     delete $hash_changeset->{'source_uuid'};


    return to_json( $hash_changeset,
                        { canonical => 1, pretty => 0, utf8 => 1 } );



}

__PACKAGE__->meta->make_immutable;
no Any::Moose;

1;