This file is indexed.

/usr/share/perl5/Catmandu/Fix/marc_set.pm is in libcatmandu-marc-perl 0.214-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package Catmandu::Fix::marc_set;

use Catmandu::Sane;
use Catmandu::Util qw(:is);
use Carp qw(confess);
use Moo;
use Catmandu::Fix::Has;

has marc_path      => (fix_arg => 1);
has value          => (fix_arg => 1);
has record         => (fix_opt => 1);

sub emit {
    my ($self,$fixer) = @_;
    my $record_key  = $fixer->emit_string($self->record // 'record');
    my $marc_path   = $self->marc_path;

    my $field_regex;
    my ($field,$ind1,$ind2,$subfield_regex,$from,$to,$len);

    if ($marc_path =~ /(\S{3})(\[(.)?,?(.)?\])?([_a-z0-9])?(\/(\d+)(-(\d+))?)?/) {
        $field          = $1;
        $ind1           = $3;
        $ind2           = $4;
        if (defined $5) {
            $subfield_regex = "$5";
        }
        else {
            $subfield_regex = ($field =~ /^LDR|^00/) ? "_" : "a";
        }
        $from           = $7;
        $to             = $9;
        $len = defined $to ? $to - $from + 1 : 1;
    }
    else {
        confess "invalid marc path";
    }

    my $perl = "";

    # Find out if we need to insert a literal value or a value from a JSON path
    my $value;

    if ($self->value =~ /^\$\.(\S+)$/) {
        my $path = $fixer->split_path($1);
        my $key  = pop @$path;
        $value =  $fixer->generate_var;
        $perl .= $fixer->emit_declare_vars($value, '""');
        $perl .= $fixer->emit_walk_path($fixer->var, $path, sub {
            my $var = shift;
            $fixer->emit_get_key($var, $key, sub {
                my $var = shift;
                "${value} = ${var};";
            });
        });
    }
    else {
        $value = $fixer->emit_string($self->value);
    }
    ##############

    $field_regex = $field;
    $field_regex =~ s/\*/./g;

    my $var  = $fixer->var;

    $perl .= $fixer->emit_foreach("${var}->{${record_key}}", sub {
        my $var  = shift;
        my $perl = "";

        $perl .= "next unless is_value ${value};";
        $perl .= "next if ${var}->[0] !~ /${field_regex}/;";

        if (defined $ind1) {
            $perl .= "next if (!defined ${var}->[1] || ${var}->[1] ne '${ind1}');";
        }
        if (defined $ind2) {
            $perl .= "next if (!defined ${var}->[2] || ${var}->[2] ne '${ind2}');";
        }

        my $i = $fixer->generate_var;
        my $set_subfields = sub {
                my $start = shift;
                my $found = $fixer->generate_var;
                my $perl  = "my ${found} = 0;".
                            "for (my ${i} = ${start}; ${i} < \@{${var}}; ${i} += 2) {".
                                "if (${var}->[${i}] eq '${subfield_regex}') {";
                if (defined $from) {
                    $perl  .=        "substr(${var}->[${i}+1],$from,$len) = ${value};";
                }
                else {
                    $perl  .=        "${var}->[${i}+1] = ${value};";
                } 
                                
                $perl .=             "${found} = 1;";
                $perl .=        "}".
                            "}";
                $perl .=    "if (${found} == 0) {".
                                "push(\@${var},'${subfield_regex}',${value});".
                            "}";
                $perl;
        };

        $perl .= "if (${var}->[0] =~ /^LDR|^00/) {";
        $perl .= $set_subfields->(3);

        # Old Catmandu::MARC contained a bug/feature to allow
        # for '_' subfields in non-control elements ..for backwards
        # compatibility we ignore them
        $perl .= "} elsif (defined ${var}->[5] && ${var}->[5] eq '_') {";
        $perl .= $set_subfields->(5);
        $perl .= "} else {";
            
        $perl .= $set_subfields->(3);
        $perl .= "}";

        $perl;
    });

    $perl;
}

=head1 NAME

Catmandu::Fix::marc_set - set a marc value of one (sub)field to a new value

=head1 SYNOPSIS

    # Set a field in the leader
    if marc_match('LDR/6','c')
        marc_set('LDR/6','p')
    end

    # Set all the 650-p fields to 'test'
    marc_set('650p','test')

    # Set the 100-a subfield where indicator-1 is 3
    marc_set('100[3]a','Farquhar family.')

    # Copy data from another field in a subfield
    marc_set('100a','$.my.deep.field')

=head1 DESCRIPTION

Read our Wiki pages at L<https://github.com/LibreCat/Catmandu/wiki/Fixes> for a complete
overview of the Fix language.

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;