/usr/share/doc/libclass-gomor-perl/examples/my-class.pl is in libclass-gomor-perl 1.03-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 | # Create a base class in BaseClass.pm
package My::BaseClass;
require Class::Gomor::Array;
our @ISA = qw(Class::Gomor::Array);
our @AS = qw(attribute1 attribute2);
our @AA = qw(attribute3 attribute4);
our @AO = qw(other);
# Create indices and accessors
My::BaseClass->cgBuildIndices;
My::BaseClass->cgBuildAccessorsScalar(\@AS);
My::BaseClass->cgBuildAccessorsArray(\@AA);
# You should initialize yourself array attributes
sub new { shift->SUPER::new(attribute3 => [], attribute4 => [], @_) }
sub other {
my $self = shift;
@_ ? $self->[$self->cgGetIndice('other')] = [ split(/\n/, shift) ]
: @{$self->[$self->cgGetIndice('other')]};
}
# Create a subclass in SubClass.pm
package My::SubClass;
our @ISA = qw(My::BaseClass);
our @AS = qw(subclassAttribute);
My::SubClass->cgBuildIndices;
My::SubClass->cgBuildAccessorsScalar(\@AS);
sub new {
shift->SUPER::new(
attribute1 => 'val1',
attribute2 => 'val2',
attribute3 => [ 'val3', ],
attribute4 => [ 'val4', ],
other => [ 'none', ],
subclassAttribute => 'subVal',
);
}
# A program using those classes
package main;
my $new = My::SubClass->new;
my $val1 = $new->attribute1;
my @values3 = $new->attribute3;
my @otherOld = $new->other;
$new->other("str1\nstr2\nstr3");
my @otherNew = $new->other;
print "@otherNew\n";
$new->attribute2('newValue');
$new->attribute4([ 'newVal1', 'newVal2', ]);
print $new->cgDumper."\n";
|