This file is indexed.

/usr/share/perl5/Catmandu/Fix/retain.pm is in libcatmandu-perl 1.0700-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
package Catmandu::Fix::retain;

use Catmandu::Sane;

our $VERSION = '1.07';

use Moo;
use namespace::clean;
use Catmandu::Fix::Has;

with 'Catmandu::Fix::Base';

has paths => (fix_arg => 'collect', default => sub {[]});

sub emit {
    my ($self, $fixer) = @_;
    my $paths   = $self->paths;
    my $var     = $fixer->var;
    my $tmp_var = $fixer->generate_var;
    my $perl    = $fixer->emit_declare_vars($tmp_var, '{}');
    for (@$paths) {
        my $path = $fixer->split_path($_);
        my $key  = pop @$path;
        $perl .= $fixer->emit_walk_path(
            $var, $path,
            sub {
                my ($var) = @_;
                $fixer->emit_get_key(
                    $var, $key,
                    sub {
                        my ($var) = @_;
                        $fixer->emit_create_path(
                            $tmp_var,
                            [@$path, $key],
                            sub {
                                my ($tmp_var) = @_;
                                "${tmp_var} = ${var};";
                            }
                        );
                    }
                );
            }
        );
    }

    # clear data
    $perl .= $fixer->emit_clear_hash_ref($var);

    # copy tmp data
    $perl .= $fixer->emit_foreach_key(
        $tmp_var,
        sub {
            my ($key) = @_;
            "${var}\->{${key}} = ${tmp_var}\->{${key}};";
        }
    );

    # free tmp data
    $perl .= "undef ${tmp_var};";
    $perl;
}

1;

__END__

=pod

=head1 NAME

Catmandu::Fix::retain - delete everything except the paths given

=head1 SYNOPSIS

   # Keep the field _id , name , title
   retain(_id , name, title)

   # Delete everything except foo.bar 
   #   {bar => { x => 1} , foo => {bar => 1, y => 2}}
   # to
   #   {foo => {bar => 1}}
   retain(foo.bar)

=head1 SEE ALSO

L<Catmandu::Fix>

=cut