Ein Modul als Objekt-Klasse

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

Counter.pm
package Counter;

use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);

sub new {
   my ($package, $startvalue, $increment) = @_;
   $startvalue = 0 unless defined $startvalue;
   $increment = 1 unless defined $increment;
   my $self = bless {
      value => $startvalue,
      incr => $increment
   }, $package;
   return $self;
}

sub inc {
   my ($self) = @_;
   return $self->{value} += $self->{incr};
}

sub dec {
   my ($self) = @_;
   return $self->{value} -= $self->{incr};
}

sub val {
   my ($self) = @_;
   return $self->{value};
}

1;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996 - 2003 Andreas Borchert, in HTML konvertiert am 01.10.2003