This file is indexed.

/usr/share/perl5/Autodia/Diagram/Class.pm is in autodia 2.14-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
package Autodia::Diagram::Class;
use strict;

=head1 NAME

Autodia::Diagram::Class - Class that holds, updates and outputs the values of a diagram element of type class.

=head1 SYNOPSIS

use Autodia::Diagram::Class;

my $Class = Autodia::Diagram::Class->new;

=head2 Description

Autodia::Diagram::Class is an object that represents the Dia UML Class element within a Dia diagram. It holds, outputs and allows the addition of attributes, relationships and methods.

=cut

use Data::Dumper;

use base qw(Autodia::Diagram::Object);

=head1 METHODS

=head2 Constructor

my $Class = Autodia::Diagram::Class->new($name);

creates and returns a simple Autodia::Diagram::Class object, containing its name and its original position (default 0,0).

=head2 Accessors

Autodia::Diagram::Class attributes are accessed through methods, rather than directly. Each attribute is available through calling the method of its name, ie Inheritances(). The methods available are : 

Operations, Attributes, Inheritances, Dependancies, Parent, and has_child. The first 4 return a list, the later return a string.

Adding elements to the Autodia::Diagram::Class is acheived through the add_<attribute> methods, ie add_inheritance().

Rather than remove an element from the diagram it is marked as redundant and replaced with a superceding element, as Autodia::Diagram::Class has highest precedence it won't be superceded and so doesn't have a redundant() method. Superclass and Component do.

=head2 Accessing and manipulating the Autodia::Diagram::Class

$Class->Attributes(), Inheritances(), Operations(), and Dependancies() all return a list of their respective elements.

$Class->Parent(), and has_child() return the value of the parent or child respectively if present otherwise a false.

$Class->add_attribute(), add_inheritance(), add_operation(), and add_dependancy() all add a new element of their respective types.

=cut

#####################
# Constructor Methods

sub new {
  my $class = shift;
  my $name = shift;
  my $self = {};
  bless ($self, ref($class) || $class);
  $self->_initialise($name);
  return $self;
}

#-------------------------------------------------------------------------

################
# Access Methods

sub Dependancies {
  my $self = shift;
  if (defined $self->{"dependancies"}) {
    my @dependancies = @{$self->{"dependancies"}};
    return @dependancies;
  } else {
    return;
  }
}


sub add_dependancy {
  my $self = shift;
  my $new_dependancy = shift;
  my @dependancies;

  if (defined $self->{"dependancies"}) {
    @dependancies = @{$self->{"dependancies"}};
  }

  push(@dependancies, $new_dependancy);
  $self->{"dependancies"} = \@dependancies;

  return scalar(@dependancies);
}

sub Inheritances {
  my $self = shift;
  if (ref $self->{"inheritances"}) {
    return $self->{"inheritances"};
  } else {
    return undef;
  }
}

sub add_inheritance {
  my $self = shift;
  my $new_inheritance = shift;
  my @inheritances;

  if (defined $self->{"inheritances"}) {
    @inheritances = @{$self->{"inheritances"}};
  }

  push(@inheritances, $new_inheritance);
  $self->{"inheritances"} = \@inheritances;
  $self->Parent($new_inheritance->Id);

  return scalar(@inheritances);
}


sub Relations {
  my $self = shift;
  return (ref $self->{"relations"}) ? @{$self->{"relations"}} : () ;
}

sub add_relation {
  my $self = shift;
  my $new_relation = shift;
  $self->{relations} ||= [];
  push(@{$self->{relations}}, $new_relation);
  return 1;
}


sub Attributes {
  my $self = shift;

  if (defined $self->{"attributes"}) {
    my @attributes = @{$self->{"attributes"}};
    return \@attributes;
  } else {
    return;
  }
}

sub add_attribute {
  my $self = shift;
  my %new_attribute = %{shift()};

  # discard new attribute if duplicate
  my $discard = 0;
  foreach my $attribute ( @{$self->{"attributes"}} ) {
    my %attribute = %$attribute;
    if ($attribute{name} eq $new_attribute{name}) {
      $discard = 1;
    }
  }

  unless ($discard) {
    push (@{$self->{"attributes"}},\%new_attribute);
    $self->_set_updated("attributes");
    $self->_update;
  }

  return scalar(@{$self->{"attributes"}});
}

sub has_child {
  my $self   = shift;
  my $child  = shift;
  my $return = 0;

  if (defined $child) {
    $self->{"child"} = $child;
  } else {
    $return = $self->{"child"};
  }
}

sub Parent {
  my $self   = shift;
  my $parent = shift;
  my $return = 0;

  if (defined $parent) {
    $self->{"parent"} = $parent;
  } else {
    $return = $self->{"parent"};
  }
}

sub replace_superclass {
  my $self       = shift;
  my $superclass = shift;

  if (ref ($superclass->Inheritances)) {
    my @inheritances = @{$superclass->Inheritances};
    foreach my $inheritance (@inheritances) {
      $inheritance->Parent($self->Id);
    }
  }

  if (ref ($superclass->Relations)) {
    my @relations = @{$superclass->Relations};
    foreach my $relation (@relations) {
      $relation->Parent($self->Id);
    }
  }

  return 1;
}

sub replace_component {
  my $self = shift;
  my $component = shift;

  if (ref ($component->Dependancies) ) {
    my @dependancies = $component->Dependancies;
    foreach my $dependancy (@dependancies) {
      $dependancy->Parent($self->Id);
    }
  }

  return 1;
}

sub Operations {
  my $self = shift;

  if (defined $self->{"operations"}) {
    my @operations = $self->{"operations"};
    return @operations;
  } else {
    return;
  }
}

sub add_operation {
  my $self = shift;
  my $operation = shift();
  $operation->{_id} = ( ref $self->{"operations"} ) ? scalar @{$self->{"operations"}} : 0 ;
  push (@{$self->{"operations"}},$operation);
  $self->{operation_index}{$operation->{name}} = $operation;

  $self->_set_updated("operations");
  $self->_update;

  return scalar(@{$self->{"operations"}});
}

sub get_operation {
    my ($self, $name) = @_;
    return $self->{operation_index}{$name};
}

sub update_operation {
    my $self = shift;
    my $operation = shift;
    
    $self->{"operations"}[$operation->{_id}] = $operation;
    $self->{operation_index}{$operation->{name}} = $operation;

    $self->_set_updated("operations");
    $self->_update;

    return;
}

sub Realizations {
  my $self = shift;
  if( defined $self->{"realizations"} ) {
    my @realizations = @{ $self->{"realizations"} };
    return @realizations;
  }
  else {
    return;
  }
}
 
sub add_realization {
  my $self            = shift;
  my $new_realization = shift;
  my @realizations;
 
  if( defined $self->{"realizations"} ) {
    @realizations = @{ $self->{"realizations"} };
  }
 
  push( @realizations, $new_realization );
  $self->{"realizations"} = \@realizations;
 
  return scalar(@realizations);
}


#-----------------------------------------------------------------------

##################
# Internal Methods

# over-rides method in DiagramObject
sub _initialise {
  my $self = shift;
  $self->{"name"} = shift;
  $self->{"type"} = "class";
  $self->{"top_y"} = 1;
  $self->{"left_x"} = 1;
  $self->{"width"} = 2; # arbitary
  $self->{"height"} = 2; # arbitary
  #$self->{"operations"} = [];
  #$self->{"attributes"} = [];
  $self->{operation_index} = {};

  return 1;
}

sub _update {
  my $self = shift;

  my %updated = %{$self->{_updated}};

  if ($updated{"attributes"}) {
    my $longest_element = ($self->{"width"} -1) / 0.5;
    my @attributes = @{$self->{"attributes"}};
    my $last_element = pop @attributes;
    if (length $last_element > $longest_element) {
      $self->{"width"} = (length $last_element * 0.5) + 1;
    }
    $self->{height} += 0.8;
  }

  if ($updated{"operations"}) {
    my $longest_element = ($self->{width} -1) / 0.5;
    my @operations = @{$self->{"operations"}};
    my $last_element = pop @operations;
    if (length $last_element > $longest_element) {
      $self->{"width"} = (length $last_element * 0.5) + 1;
    }
    $self->{"height"} += 0.8;
  }

  undef $self->{"_updated"};

  return 1;
}


1;

##############################################################################


=head2 See Also

L<Autodia::DiagramObject>

L<Autodia::Diagram>

L<Autodia::DiagramSuperclass>

L<Autodia::DiagramInheritance>

=head1 AUTHOR

Aaron Trevena, E<lt>aaron.trevena@gmail.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2004 by Aaron Trevena

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.1 or,
at your option, any later version of Perl 5 you may have available.

=cut

########################################################################