develooper Front page | perl.beginners | Postings from January 2002

who is the method cop?

Skip Montanaro
January 7, 2002 10:29
who is the method cop?
Message ID:

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

    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) = @_;

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?


Skip Montanaro ( - Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About