~~David~~ has asked for the wisdom of the Perl Monks concerning the following question:
I have done this already using Moose, but I can't use Moose for this application. Maybe this is not even possible using Class::Accessor, I couldn't find anything saying it was or wasn't. Thanks for any help.package KLARF; use strict; use warnings; use base qw(Class::Accessor); # set up initial accessors KLARF->mk_accessors( qw( state debug current_list ) ); # overload state accessor to print current state in debug mode sub state { my $self = shift; if ( @_ ){ $self->{state} = shift; print "$self->{state}\n" if $self->{debug}; return $self->{state}; } else { print "$self->{state}\n" if $self->{debug}; return $self->{state}; } } sub kv { my $self = shift; my $key = shift; my $value = shift; $key = lc $key; if ( $self->{state} eq 'RECORD' ){ $value =~ s/\"//g; chomp $value; } if ( $self->{state} eq 'FIELD' ){ $value =~ s/\"//g; $value =~ s/\s//g; my @values = split /,/, $value; $value = \@values; } if ( $self->{debug} ){ print uc "Key is $key, Value is $value\ +n"}; $self->{$key} = $value; KLARF->make_accessor( $key ); # this doesn't seem to work??? }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dynamic Method Generation Using Class::Accessor
by ikegami (Patriarch) on Aug 13, 2009 at 15:27 UTC | |
|
Re: Dynamic Method Generation Using Class::Accessor
by moritz (Cardinal) on Aug 13, 2009 at 15:35 UTC | |
by ~~David~~ (Hermit) on Aug 13, 2009 at 18:58 UTC | |
by moritz (Cardinal) on Aug 14, 2009 at 07:16 UTC |