in reply to How could we "implement" Open Classes in Perl ?

Perl classes are based on packages, which are by nature open. So e.g. to add a foo() method to the CGI class you can do
package main; use strict; use warnings; use CGI; package CGI; sub foo { my $self = shift; return $self->p('foo'); } package main; my $cgi = CGI->new; print $cgi->foo() . "\n";

Replies are listed 'Best First'.
Re^2: How could we "implement" Open Classes in Perl ?
by Alien (Monk) on Jun 27, 2008 at 08:07 UTC
    Thank you for this great example.

      Since you have direct access to the package via its namespace, you don't even need the package switching. This works too–

      use CGI; my $cgi = CGI->new; print $cgi->foo(), "\n"; sub CGI::foo { my $self = shift; return $self->p('foo'); }