On Wed, 6 Jul 2005, Matt Sergeant wrote:

On 6 Jul 2005, at 16:51, Charlie Brady wrote:

Thoughts?

I'd rather just eval those subs into existence than need another CPAN module to do something so easy.

Something like:

BEGIN {
my @fields = qw( remote_host remote_ip remote_info remote_port
local_ip local_port
relay_client hello hello_host)

That's really very little different to what Class:Frame does. Frame.pm is 280 lines, including POD.

Here's the accessors/mutators instantiation:

...
        # Inject accessors/mutators
        foreach my $arg (keys %args) {

                *{$pkg.'::set_'.$arg} =
eval('sub { my $self = shift; $self->_setter(name => "'.$arg.'", val => shift);}');

                *{$pkg.'::get_'.$arg} =
eval('sub { my $self = shift; return $self->_getter(name => "'.$arg.'");}');

                *{$pkg.'::get_'.$arg.'_default'} =
eval('sub { my $self = shift; return $self->_FIELDS->{'.$arg.'};}');

                *{$pkg.'::'.$arg} = *{$pkg.'::get_'.$arg};
        }
}

sub _setter {
        my $self = shift;
        my %args = @_;
        my $name = $args{name} or die "name argument is missing";
        $self->{$name} = $args{val};
}
...

Reply via email to