use strict; use warnings; use MooX::Struct Document => [ qw($fileID $filename @tags) ]; Document => [ tags => [ is => 'rw', required => 1 ] ]; # the line above produces... # Useless use of a constant ("Document") in void context at testmoo.pl line 5. # Useless use of anonymous list ([]) in void context at testmoo.pl line 5. # ...instead of making the struct members writeable my @doc_list; # simulate processing two files "by hand" for testing # first document my $filenumber = 1; my $filename = "PetsFile"; my @filetags; # create, allocate and store struct in doc_list my $doc = Document[ $filenumber, $filename, @filetags]; push @doc_list, $doc; # <-- this is line 17, and the script fails with the message: # tags is a read-only accessor at (eval 129) line 17. # second document ++$filenumber; $filename = "BirdsFile"; # create, allocate and store struct in doc_list my $doc = Document[ $filenumber, $filename, @filetags]; push @doc_list, $doc; # simulated processing in a later pass # - this involves modifying struct members after creation my $tag = "Cats"; push @filetags, $tag; $tag = "Dogs"; push @filetags, $tag; $doc_list[1]->tags ( @filetags); my @filetags; # new my frees variable and resets to undef again $tag = "Doves"; push @filetags, $tag; $tag = "Eagles"; push @filetags, $tag; $tag = "Shantaks"; push @filetags, $tag; $doc_list[2]->tags ( @filetags); # finally check whether this worked as intended for (1..2) { # my $$doc_pointer = \@doc_list[ @_ ]; # mmh a pointer/hard ref would be nice... # could then avoid to use the index as in the code below... # need to learn how to do this printf "File ID: %s\n", $doc_list[ @_ ]->fileID; printf "Filename: %s\n", $doc_list[ @_ ]->filename; printf "Tags: %s\n", join(', ', @{ $doc_list[ @_ ]->tags }); }