telcontar has asked for the wisdom of the Perl Monks concerning the following question:
At the time, this was created as a data structure because we needed a way to iterate through it and easily call a subset of the coderefs, and process the returned data.$CODEREFS{1}{1} = { property => 'value', ... cref => sub { ... } }; $CODEREFS{1}{2} = { property => 'value', ... cref => sub { ... } }; ...
Surely there must be a more elegant solution? Any help would be greatly appreciated,package Blah; use strict; use warnings; require 5; use Carp; our %CODEREFS; $CODEREFS{1}{1} = { property => 'value', cref => sub { my $self = shift; } }; sub new { my $class = shift; my $self = { crefs => \%CODEREFS }; bless $self, $class; } sub access { my $self = shift; my ($a, $b) = (shift, shift); $self->{crefs}{$a}{$b}{cref}->($self, @_); } package main; use strict; my $blah = Blah->new(); $blah->access(1, 1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Refactoring a module with many anonymous subrefs as an OO module
by Ovid (Cardinal) on Nov 21, 2007 at 12:32 UTC | |
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 | |
|
Re: Refactoring a module with many anonymous subrefs as an OO module
by Corion (Patriarch) on Nov 21, 2007 at 12:21 UTC | |
by telcontar (Beadle) on Nov 21, 2007 at 12:40 UTC |