This file is indexed.

/usr/share/perl5/SWISS/BaseClass.pm is in libswiss-perl 1.67-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
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
package SWISS::BaseClass;

use vars qw($AUTOLOAD @ISA @EXPORT_OK);
use Exporter;
use Carp;
use strict;
use Data::Dumper;

# Place functions/variables you want to *export*, ie be visible from the caller package into @EXPORT_OK
@EXPORT_OK = qw();

use vars qw { @ISA $AUTOLOAD %fields };
 
BEGIN {
    # Our inheritance
    @ISA = ( 'Exporter' );

    # our data members
    %fields = (_dirty => undef,
	       evidenceTags => undef,
	       indentation => undef,
	      );
}
# makes it appear that there are functions 
# of the same names as the member variables
# which get and set their value
sub AUTOLOAD {
    my $name = $AUTOLOAD;
    $name =~ /::DESTROY/ && return;
    $name =~ s/.*://;

    my $self = shift;
    my $type = ref($self) || confess "Cannot use the non-object $self to find $name\n";

    unless (exists $self->{$name} ) {
        confess "In type $type, can't access $name.  Incorrect function or member name.\n";
	return undef;
    }
    if (@_) {
      # something is being set, so the object is dirty.
      $self->{_dirty} = 1;
      return $self->{$name} = shift;
    } else {
	return $self->{$name};
    }
}

# reblesses a reference to a base class object into your class
# adds the apropreate members with their default values as
# defined in the %fields hash, and modified by initialize
sub rebless {
  no strict 'refs';
  my $self = shift || confess "You must parse an object to rebless";
  my $class = shift || confess "You must give a package to rebless $self into";
  
  %{$self} = (%{$self}, %{$class."::fields"});
  bless $self, $class;
  $self->initialize();
  return $self;
}

# returns a myBase object
# use this for all derived classes
sub new {
    my $ref = shift;
    my $class = ref($ref) || $ref;
    my $self = {};
    
    rebless($self, $class);

    return $self;
}

# put any code that you want which initializes the virgin values of
# your member variables in here
sub initialize {
  my $self = shift;

  $self->{'evidenceTags'} = '{}';
  $self->{'indentation'} = undef;
  
  return $self;
}

sub update {
  my $self = shift;
  return $self;
}
  

# checks for name clashes between a class and all of it's base classes.
# Supports multiple inheritance, and multi-level inheritance
#
sub check4Clashes {
    no strict 'refs';
    my $class = shift;
    my @fields = keys %{$class."::fields"};
    my @parents = @{$class."::ISA"};
    my $parent;
    my $override;
    my @found = ();

    foreach $parent (@parents) {
	$override = ($parent->can('_containsFields') && $parent->_containsFields(@fields));
	$override && push @found, @$override;
    }

    if(@found) {
	confess "$class contains member variables that clash with base class members\n",
	map { "\t$_\n"} @found;
    }
}

# helper function for checkClashes
# less said about this the better
#
sub _containsFields {
    no strict 'refs';
    my $class = shift;
    my @fields = @_;
    my $field;
    my @parents = @{$class."::ISA"};
    my $parent;
    my $override;
    my @found = ();

    foreach $field (@fields) {
	if(exists ${$class."::fields"}{$field}) {
           push @found, $class."::".$field;
	}
    }

    foreach $parent (@parents) {
	$override = ($parent->can('_containsFields') && $parent->_containsFields(@fields));
	$override && push @found, @$override;
    }

    (@found) && return \@found;
    return undef;
}

# added by hhe@ebi.ac.uk
sub equal {
  my ($self, $other) = @_;

  return Dumper($self) eq Dumper($other);
};  

# Returns a "deep copy" of the object
sub copy {
  my $self = shift;
  my $new;

  eval Data::Dumper->Dump([$self], [qw(new *ary)]);
  return $new;
}

# Evidence tag handling
sub setEvidenceTags {
  my $self = shift;
  my @tags = @_;
  
  $self->{'evidenceTags'} = '{' . (join ',', @tags) . '}';
  $self->{'_dirty'} = 1;
  return;
}

sub addEvidenceTag {
  my $self = shift;
  my $tag = shift;
  unless ($self->{'evidenceTags'} =~ /[\{\,]$tag[\}\,]/) {
    if ($self->{'evidenceTags'} eq '{}') {
      $self->{'evidenceTags'} = '{' . $tag . '}';
    } else {
      $self->{'evidenceTags'} =~ s/\}/\,$tag\}/;      
    }
  }
  $self->{'_dirty'} = 1;
  return;
}

sub deleteEvidenceTag {
  my $self = shift;
  my $tag = shift;
  $self->{'evidenceTags'} =~ s/([\{\,])$tag([\,\}])/$1$2/;
  $self->{'evidenceTags'} =~ s/\,\,/\,/;
  $self->{'evidenceTags'} =~ s/\,\}/\}/;
  $self->{'evidenceTags'} =~ s/\{\,/\{/;
  $self->{'_dirty'} = 1;
  return;
}

sub hasEvidenceTag {
  my $self = shift;
  my $tag = shift;
  return  $self->{'evidenceTags'} =~ /[\{\,]$tag[\}\,]/;
}

sub getEvidenceTags {
  my $self = shift;
  my $tmp = $self->{'evidenceTags'};
  $tmp =~ tr/\{\}//d;
  return split /\,/, $tmp;
}

sub getEvidenceTagsString {
  my $self = shift;
  my $tmp = $self->{'evidenceTags'};
    
  if ($tmp eq '{}') {
    return '';
  } else {
    return $tmp;
  }
}

# Force Swissknife to reformat an object, even if it has not been modified.
sub reformat {
  my $self = shift;
  $self->{_dirty} = 1;
}

1;

__END__

=head1 NAME

SWISS::BaseClass

=head1 DESCRIPTION

This class is designed to impliment many of the properties that you
expect in inheritance.  All the housekeeping functions are defined
in this module.  See the notes on use for a description of how to
make use of it.

=head1 Functions

=over

=item new

Returns a new SWISS::BaseClass object.

=item rebless

Converts a base class into your class!  Call as $self->rebless($class) where
$self is a base class object.  It returns $self, reblessed, with the correct
member variables.

=item initialize

Override this in each derived class to provide class specific initialization.
For example, initialize may put arrays into member variables that need them.
You must provide an initialize function.

=item reformat

Some line objects are implementing "lazy writing". This means that on writing an entry, they are only reformatted if they have been modified. The method reformat forces an object to be reformatted even if its content has not been modified. This may be useful e.g. to make sure the current formatting rules are applied.

=item setEvidenceTags @array

Sets the evidence tags of the object to the list passed in @array. 

=item addEvidenceTag string

Adds the evidence tag to the object.

=item deleteEvidenceTag string

Deletes the evidence tag from the object. 

=item hasEvidenceTag string

returns true if the object has the evidence tag.

=item getEvidenceTags

returns the array of evidence tags of the object

=item Check4Clashes

This function checks your classes member variable list for clashes with any class
that it inherits from (any class that can(_containsFields) returns true on!).  If it
detects that in any base class that any data members have been already defined,
it dies with a listing of the variables already used.

It stops searching a root of an inheritance hierachy when it can find no baseclasses that
support _containsFields.  It will find all clashes in an entire inheritance tree.

So in the inheritance hierachy of

 SWISS::BaseClass -> A -> B -\
                             > E
 SWISS::BaseClass -> C -> D -/

where E is the most derived class, if E contains names that clash with A members
and names that clash with B members, both the A and B member clashes will be reported.

If there were clashes with B and C, say, then again, all of the clashes would be reported.

=item _containsFields

This function is responsible for comparing a classes fields with the set in the
calling package.  This implimentation will work for cases where all of the
classes that contribute fields are derived from SWISS::BaseClass.  You may wish to
make your own class fit this interface, so what follows is an interface API.

_containsFields assumes that the first argument is the package that it is being called in.
The following arguments are taken to be a list of fields which to check are not found
in members of the current package.

It should return either C<undef> or a reference to an array of name clashes in the format
C<package::variable>.  It should call it's self for each parental class that supports this
function.

So it would look something like
  _containsFields {
    my $class = shift;
    my @toCheck = @_;

    foreach @toCheck {
      check that they are not in me.  If they are, add them to the list of clashes to return.
    }

    add all base class clashes to your list of clashes

    if there were name clashes return a reference to them

    otherwise return undef
  }

=item equal

If two objects are equal, it returns true.

Warning: This funktion compares two objects using a simple dump in Perl format, see Data::Dumper module. The comparison also takes private variables into account. Therefore: If the method 'equal' returns true, the objects are guaranteed to be equal, but it might return false although the two objects are equal in they public attributes.

=item copy

Returns a "deep copy" of the object.

=back

=head1 A skeletal derived class

 package myDerived;

 use vars qw ( @ISA %fields );

 BEGIN {
    @ISA = ('SWISS::BaseClass');

    %fields = (
	       'i' => 1,
	       'hash' => undef
	       );

    myDerived->check4Clashes();
 }

 sub new {
    print "myDerived::new(@_)\n";
    my $class = shift;
    my $self = new SWISS::BaseClass;
    
    $self->rebless ($class);
    
    return $self;
 }

 sub initialize {
    my $self = shift;
    $self->{'hash'} = {};
 }

A class derived from myDerived would just substitute the name myDerived
for SWISS::BaseClass.  Hey presto - all sorted!