in reply to Refactoring a module with many anonymous subrefs as an OO module
Not really sure if this will help in your case, but here's a little trick with coderefs that many people don't know about.
#!/usr/bin/perl use strict; use warnings; { package Foo; sub new { bless {} => shift } sub name { return 'telcontar' } } my $method = sub { return shift->name }; print Foo->new->$method;
That should print 'telcontar'. In other words, you can call your coderefs as methods on your object and the first argument in @_ will be your object, as expected.
Update: that changes your code to this:
sub access { my ( $self, $x, $y ) = splice @_, 0, 3; my $method = $self->{crefs}{$x}{$y}; return $self->$method(@_); }
Cheers,
Ovid
New address of my CGI Course.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Refactoring a module with many anonymous subrefs as an OO module
by telcontar (Beadle) on Nov 21, 2007 at 13:32 UTC | |
by Ovid (Cardinal) on Nov 21, 2007 at 20:13 UTC | |
by telcontar (Beadle) on Nov 22, 2007 at 09:38 UTC |