LibreCat / Dancer-Plugin-Catmandu-SRU

SRU server backed by a searchable Catmandu::Store
http://librecat.org
Other
1 stars 1 forks source link

Not an ARRAY reference at /usr/local/share/perl/5.28.1/Catmandu/Fix.pm line 59 #12

Open danmichaelo opened 3 years ago

danmichaelo commented 3 years ago

Got this error:

Not an ARRAY reference at /usr/local/share/perl/5.28.1/Catmandu/Fix.pm line 59.

/usr/local/share/perl/5.28.1/Catmandu/Fix.pm around line 59

56     my $fixes_arg = $self->_fixes;
57     my $fixes     = [];
58 
59     for my $fix (@$fixes_arg) {
60 
61         if (is_code_ref($fix)) {
62             push @$fixes, require_package('Catmandu::Fix::code')->new($fix);

despite fix being an array:

'Catmandu::SRU':
    store: es_store
    bag: oai
    default_record_schema: marc21
    record_schemas:
      -
        identifier: info:lc/xmlns/marcxchange-v1
        name: marc21
        title: MARC 21
        template: generic_xml.tt
        fix:
          - remove_marc21nor.fix

When i added use Data::Dumper; print STDERR Dumper($setting); after my $setting = hash_merge($s, \%opts);, I noticed that 'fix' had already been turned into an object:

   'record_schemas' => [
sru_1  |                                 {
sru_1  |                                   'identifier' => 'info:lc/xmlns/marcxchange-v1',
sru_1  |                                   'template' => 'generic_xml.tt',
sru_1  |                                   'name' => 'marc21',
sru_1  |                                   'title' => 'MARC 21',
sru_1  |                                   'fix' => bless( {
sru_1  |                                                     '_fixes' => [
sru_1  |                                                                   'remove_marc21nor.fix'
sru_1  |                                                                 ]
sru_1  |                                                   }, 'Catmandu::Fix' )
sru_1  |                                 },
sru_1  |                               ],

so it seems like plugin_setting is modified in-place, and then kept when the file is reloaded (when using plackup -R), and I also got the problem with starman, which I don't think reloads file while running, but perhaps something with threads, I have no clue really, since I don't know the inner workings of starman at all.

Possible solutions

It does help to clone the object before making any modifications:

+use Clone 'clone';

sub sru_provider {
    my ($path, %opts) = @_;

-    my $setting = hash_merge(plugin_setting, \%opts);
+    my $setting = clone hash_merge(plugin_setting, \%opts);

But I'm not sure if this is considered a good approach? (Not sure if there could be risk for recursive references or something). Would it be cleaner to store the Catmandu Fix object in a new variable instead of modifying in-place?

Let me know what you think.