expand
and extend
Rindolf will provide two operators named expand
and extend
that would enable manipulating such namespaces efficiently.
expand
takes an entire class and dumps a cope of all of its package-scope symbols into the current namespace. extend
takes a class reference and extends with another class. Together they can be used to manipulate classes.
Here is a similar example with some expand
and extend
magic:
my $class1 = class { sub hello { my $you = shift; print "Hello $you!\n"; } }; my $class2 = class { sub goodbye { my $you = shift; print "Goodbye!\n"; } }; class You { expand($class1); expand($class2); sub message { my $you = shift; my $message = shift; hello($you); print "$message\n"; goodbye($you); } }; my $object_class = class { sub new { my $class = shift; my $name = shift; my $self = {}; bless($self, $class); $self->{'name'} = $name; pt_return $self; } sub msg { my $self = shift; my $message = shift; pt_return message($self->{'name'}, $msg); } }; extend $object_class, typeref{CLASS}{YOU}; my $person = $object_class->new("Muli"); $person->msg("Time to track system calls!");
Note the typeref
operator which is a generic way of casting references, that is introduced due to the fact that we are running out of special characters in the keyboard (:-)). It will be available for hashes, arrays and others language primitives.