5 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package test;
use strict;
sub new{
my $class = shift;
my $self = {};
$self->{NAME}=undef;
$self->{PROPERTIES}=[];
bless($self, $class);
return $self;
}
sub name {
my $self = shift;
if (@_) {$self ->{NAME}=shift};
return $self->{NAME};
}
sub properties {
my $self = shift;
if (@_) {@{$self->{PROPETIES}} = @_}
return @{$self->{PROPERTIES}};
}
1;
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
package TestObjects; use strict; use warnings; my @objects; sub new{ my ($class) = @_; my $self = {}; bless $self,$class; push @objects,$self; return $self; } sub name{ my ($self,$name) = @_; $self->{NAME} = $name if defined $name; return $self->{NAME}; } sub properties{ my ($self,@properties) = @_; $self->{PROPERTIES} = [@properties] if @properties; my @array; @array = @{$self->{PROPERTIES}} if defined $self->{PROPERTIES}; return @array; } sub find{ my ($class,$name) = @_; for my $obj( @objects ){ if( $obj->name eq $name ){ print $obj->name," -> ",join("..",$obj->properties),"\n"; } } } 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; use TestObjects; my $obj1 = TestObjects->new(); $obj1->name( 'Jason' ); $obj1->properties( 'a','b' ); my $obj2 = TestObjects->new(); $obj2->name( 'Hugo' ); TestObjects->find( 'Jason' );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package TestObjects;
...
my @objects;
my $id;
sub new{
my ($class) = @_;
my $self = {id=>++$id};
bless $self,$class;
push @objects,$self;
return $self;
}
sub first { 1 }
sub last { $id }
...
1;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package TestObjects;
...
my @objects;
sub new{
my ($class) = @_;
my $self = {id=>$#objects+1};
bless $self,$class;
push @objects,$self;
return $self;
}
sub first { 0 }
sub last { $#objects }
...
1;
5 Einträge, 1 Seite |