> I'm trying to figure out Perl's object-oriented features.
> I'm a long-time Python Programmer, so I'm well-versed in
> its notion of OO programming, but Perl's method
> definition stuff seems a bit "loose".  All of my Perl
> programming is in a Mason context, so that's where I'll
> pull an example.  Let's see, here's a simple enough
> example.  These two methods are from
> HTML::Mason::ApacheHandler.
>
> [SNIP]
> 
>     # Override flush_buffer to also call $r->rflush
>     sub flush_buffer
>     {
>         my ($self, $content) = @_;
>         $self->SUPER::flush_buffer($content);
>         $self->apache_req->rflush;
>     }
> 
> I understand the assignment to $self and $class.  What
> I don't understand is how new and flush_buffer are
> associated with a specific class.  For example, is there
> anything that keeps me from calling flush_buffer with an
> instance of a class other than ApacheHandler or calling
> new with some other class?  Should the class author be
> doing some type checking?

Type checking is for wimps ;)  Do you send normally try to
send Square objects to RoundHole objects?  If you do, I bet
you didn't read the API documentation.  Most of the time it
doesn't matter, but if you care there are modules on CPAN
to add type checking.

The association between methods and classes is done by
packages.  You'll notice this example resides in the
HTML::Mason::ApacheHandler package.

To make this clear, in Perl OOP you use:

Packages as classes.
Subroutines as instance methods/class methods.
Package variables for class variables.
Blessed variables for object instances.

To be an object the package name MUST be the same as the
filename.

I think I've got all this right...

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to