RE: OO method query



Dermot <paikkos@xxxxxxxxxxxxxx> asked:
I am trying my hand at creating an package and am a bit
unsure about some of the inner working of what I've done.

I recommend http://books.perl.org/book/171


Q3) In new, can I allow for the object create being done with
more argument like my $page = new sendData(type => 'a5'). How
can you detect named arguments when a object is being created.

I have a new method

sub new {
my $class = shift;

# make arguments to new() into a hash
my %args = @_;

my $self = {};

# copy relevant named arguments from hash to $self
# while setting sensible default values.
$self->{'type'} = $args{'type'} || 'a4';

bless($self, $class);
return $self;
}

# creating new object:
my $page = sendData->new( 'type' => 'a5' );

Q2) In get_file_list is the first ARG really $self? I thought
it would be the class? However it seems to know about itself.

That's Perl OO for you. The first argument passed to a method of
a class is always the object via which the call was made.

HTH,
Thomas
.