#!/usr/bin/perl
use strict;
use warnings;
package MyObject;
sub new {
print "method 'new' called with parameters: ", join ("\n", @_ ), "\n";
my ( $class, @args ) = @_;
my $self = {};
$self -> {state} = "newly created";
bless $self, $class;
return $self;
}
sub set_state {
my ( $self, $new_state ) = @_;
$self -> {state} = $new_state;
}
sub get_state {
my ( $self ) = @_;
return $self -> {state};
}
####
# use_oo.pl
#!/usr/bin/perl
use strict;
use warnings;
use MyObject
my $object_instance = MyObject -> new();
print "Object is: ", $object_instance,"\n";
$object_instance -> set_state ( "here is a new state" );
print "Object state: ", $object_instance -> get_state(),"\n";
####
MyObject=HASH(x012345)
####
$object_instance -> set_state ( "here is a new state" );
####
MyObject::set_state ( $object_instance, "here is a new state" );