in reply to Re: goto and AUTOLOADed methods
in thread goto and AUTOLOADed methods
$self->can("SUPER::method_name");
I suppose I should explain my idea. I'm not doing autloaded accessors or anything like that. Here's a very rough idea of what I'm doing
So you pull some object out of your database and it has links to other objects but you obviously don't want to pull those objects out because that would pull out more sub objects and pretty soon, your whole database is in memory. So instead you just leave a "fake" object wherever there would be a sub object and you end up with something likepackage UnloadedObject; use Class::MethodMaker ( new_hash_init => 'new', get_set => [qw( Table Class ID )] ) sub AUTOLOAD { my $method = $AUTOLOAD; $method =~ s/.*:://; my $table = $self->Table; my $id = $self->ID; my $class = $self->Class; my $self = $_[0]; my $sub = $class->can($method) || $class->can("AUTOLOAD"); die "Can't call $method on $class" unless defined($sub); bless $self, $class; %$self = (); $table->fillFromID($self, $id); goto &$sub; }
It's actually a little more complicated than that but that's the basic idea. I don't have to worry about AUTOLOAD loops because I'm not looking in the same class.my $me = $people->getByName("fergal"); my $name = $me->Name; # nothing special my $boss = $me->Boss; # still nothing special my $boss_name = $boss->Name; # bang! magic things happen and suddenly +$boss has all it's data loaded
UpdatedI changed $self to $class in the ->can sutff
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: goto and AUTOLOADed methods
by ctilmes (Vicar) on Aug 01, 2003 at 12:47 UTC |