Subj : Re: anyone know of a language where nonexistent functions return no error? To : comp.programming From : gswork Date : Tue Jul 26 2005 07:19 am Jonathan Bartlett wrote: > > So i'm intrigued now - what do folks use the feature for? > > Another application I thought of is as a wrapper to another class. > > For example, if I wanted to trace all of the calls made on an object, I > could create a tracer class: > > package Tracer; > > sub new > { > my ($class, $traced_obj) = @_; > > my $self = { TRACED_OBJ => $traced_obj }; > bless $self, $class; > return $self; > } > > sub AUTOLOAD > { > my $name = our $AUTOLOAD; > *$AUTOLOAD = sub { my $self = shift; print STDERR "Calling $name\n"; > $self->$name(@_); } > goto &*AUTOLOAD; > } > > Then I could use it like this: > > use Tracer; > my $obj = new Tracer(new SomeOtherClass); > $obj->whatever(); /* gives a trace and then calls "whatever" on the > original object -- Completely API compatible with the original object */ > > Also you could create sort of "dynamic subclasses" which allow you to > subclass a wide variety of objects (I used to be able to think of > situations where this would be useful, but not at the moment). thanks for these examples - this latter one is something i can see the benefit of as a handy 'in code' development tool. .