At 12:27 PM 1/7/02 -0600, Skip Montanaro wrote:

>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".

Yes, we like it that way :-)

>    sub new
>     {
>         my ($class,%options) = @_;
>         my $interp = $options{interp} or die 
> "HTML::Mason::Request::ApacheHandler::new: must specify interp\n";
>         delete $options{interp};
>         my $self = $class->SUPER::new(interp=>$interp);
>         while (my ($key,$value) = each(%options)) {
>             if (exists($reqfields{$key})) {
>                 $self->{$key} = $value;
>             } else {
>                 die "HTML::Mason::Request::ApacheHandler::new: invalid 
> option '$key'\n";
>             }
>         }
>         return $self;
>     }
>
>     # 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?

Only if that class inherits from the class the method is defined 
in.  Otherwise there's no way for Perl to find that code.

>Should the class author be doing some type checking?

I've never seen anyone bother.  I suppose you could check $class or ref 
$self against __PACKAGE__ if you wanted to make sure that no-one could call 
your methods from a subclass, but that sounds very antisocial.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


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

Reply via email to