I am writing a module which reads in flat text files that are made of fields which contain a tag followed by a value (ex: Time 16:43:25; ). I know ahead of time what tags are allowed, but there are quite a few of them.
I can think of two options to write this:
1.) Write an individual accessor for each tag
2.) Do this (which is what I have done but don't know if it is alright to do>:
after 'file' => sub {
my $self = shift;
open my $FILE, "<", $self->{file};
HEADER:
while ( <$FILE> ){
my ( $tag, $value ) = $_ =~ /\s*(\w+)\s(.+)/;
my $accessor = lc $tag;
#create an accessor for each header value
has $accessor => ( is =>'ro' );
$self->{$accessor} = $value;
}
close $FILE;
};
Maybe I have the wrong idea completely, but I was just wondering if I should choose one way or the other. The Moose tutorial says you should try to
__PACKAGE__->meta->make_immutable; which my current method doesn't allow me to do...