This file is indexed.

/usr/share/perl5/KiokuDB/Backend/Serialize/JSPON/Expander.pm is in libkiokudb-perl 0.57-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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package KiokuDB::Backend::Serialize::JSPON::Expander;
BEGIN {
  $KiokuDB::Backend::Serialize::JSPON::Expander::AUTHORITY = 'cpan:NUFFIN';
}
$KiokuDB::Backend::Serialize::JSPON::Expander::VERSION = '0.57';
use Moose;
# ABSTRACT: Inflate JSPON to entry data.

use Carp qw(croak);
use Scalar::Util qw(weaken);

use KiokuDB::Entry;
use KiokuDB::Reference;

use namespace::clean -except => 'meta';

with qw(KiokuDB::Backend::Serialize::JSPON::Converter);

sub expand_jspon {
    my ( $self, $data, @attrs ) = @_;

    return $self->_expander->($data, @attrs);
}

has _expander => (
    isa => "CodeRef",
    is  => "ro",
    lazy_build => 1,
);

sub _build__expander {
    my $self = shift;

    my $expander;

    my (
        $ref_field,     $id_field,         $data_field,
        $class_field,   $tied_field,       $root_field,
        $deleted_field, $class_meta_field, $class_version_field,
        $backend_data_field
      )
      = map { my $m = $_ . "_field"; $self->$m() }
      qw(ref id data class tied root deleted class_meta class_version backend_data);

    unless ( $self->inline_data ) {
        my $data_field_re = qr/\. \Q$data_field\E $/x;

        $expander = sub {
            my ( $data, @attrs ) = @_;

            if ( my $ref = ref($data) ) {
                if ( $ref eq 'HASH' ) {
                    if ( my $id = $data->{$ref_field} ) {
                        $id =~ s/$data_field_re//;
                        return KiokuDB::Reference->new( id => $id, ( $data->{weak} ? ( is_weak => 1 ) : () ) );
                    } elsif ( exists $data->{$class_field}
                        or exists $data->{$id_field}
                        or exists $data->{$tied_field}
                    ) {
                        if ( exists $data->{$class_field} ) {
                            # check the class more thoroughly here ...
                            my ($class, $version, $authority) = (split '-' => $data->{$class_field});
                            push @attrs, class => $class;

                            push @attrs, class_meta    => $data->{$class_meta_field} if exists $data->{$class_meta_field};
                            push @attrs, class_version => $data->{$class_version_field} if exists $data->{$class_version_field};
                        }

                        push @attrs, id           => $data->{$id_field}                 if exists $data->{$id_field};
                        push @attrs, tied         => substr($data->{$tied_field}, 0, 1) if exists $data->{$tied_field};
                        push @attrs, root         => $data->{$root_field}    ? 1 : 0    if exists $data->{$root_field};
                        push @attrs, deleted      => $data->{$deleted_field} ? 1 : 0    if exists $data->{$deleted_field};
                        push @attrs, backend_data => $data->{$backend_data_field}       if exists $data->{$backend_data_field};

                        push @attrs, data => $expander->( $data->{$data_field} );

                        return KiokuDB::Entry->new( @attrs );
                    } else {
                        my %hash;

                        foreach my $key ( keys %$data ) {
                            my $unescaped = $key;
                            $unescaped =~ s/^public:://;

                            my $value = $data->{$key};
                            $hash{$unescaped} = ref($value) ? $expander->($value) : $value;
                        }

                        return \%hash;
                    }
                } elsif ( ref $data eq 'ARRAY' ) {
                    return [ map { ref($_) ? $expander->($_) : $_ } @$data ];
                }
            }

            return $data;
        }
    } else {
        $expander = sub {
            my ( $data, @attrs ) = @_;

            if ( my $ref = ref($data) ) {
                if ( $ref eq 'HASH' ) {

                    if ( my $id = $data->{$ref_field} ) {
                        return KiokuDB::Reference->new( id => $id, ( $data->{weak} ? ( is_weak => 1 ) : () ) );
                    } elsif ( exists $data->{$class_field}
                        or exists $data->{$id_field}
                        or exists $data->{$tied_field}
                    ) {
                        my %copy = %$data;

                        if ( exists $copy{$class_field} ) {
                            # check the class more thoroughly here ...
                            my ($class, $version, $authority) = (split '-' => delete $copy{$class_field});
                            push @attrs, class => $class;

                            push @attrs, class_meta => delete $copy{$class_meta_field} if exists $copy{$class_meta_field};
                        }

                        push @attrs, id      => delete $copy{$id_field}              if exists $copy{$id_field};
                        push @attrs, tied    => delete $copy{$tied_field}            if exists $copy{$tied_field};
                        push @attrs, root    => delete $copy{$root_field}    ? 1 : 0 if exists $copy{$root_field};
                        push @attrs, deleted => delete $copy{$deleted_field} ? 1 : 0 if exists $copy{$deleted_field};

                        push @attrs, data => $expander->( \%copy );

                        return KiokuDB::Entry->new( @attrs );
                    } else {
                        my %hash;

                        foreach my $key ( keys %$data ) {
                            my $unescaped = $key;
                            $unescaped =~ s/^public:://;

                            my $value = $data->{$key};
                            $hash{$unescaped} = ref($value) ? $expander->($value) : $value;
                        }

                        return \%hash;
                    }
                } elsif ( ref $data eq 'ARRAY' ) {
                    return [ map { ref($_) ? $expander->($_) : $_ } @$data ];
                }
            }

            return $data;
        }
    }

    my $copy = $expander;
    weaken($expander);

    return $copy;
}

__PACKAGE__->meta->make_immutable;

__PACKAGE__

__END__

=pod

=encoding UTF-8

=head1 NAME

KiokuDB::Backend::Serialize::JSPON::Expander - Inflate JSPON to entry data.

=head1 VERSION

version 0.57

=head1 SYNOPSIS

    my $c = KiokuDB::Backend::Serialize::JSPON::Expander->new(
        id_field => "_id",
    );

    my $entry = $c->collapse_jspon($hashref);

=head1 DESCRIPTION

This object is used by L<KiokuDB::Backend::Serialize::JSPON> to expand JSPON
compliant hash references to L<KiokuDB::Entry> objects.

=head1 ATTRIBUTES

See L<KiokuDB::Backend::Serialize::JSPON::Converter> for attributes shared by
L<KiokuDB::Backend::Serialize::JSPON::Collapser> and
L<KiokuDB::Backend::Serialize::JSPON::Expander>.

=head1 METHODS

=over 4

=item expand_jspon $hashref

Recursively inflates the hash reference, returning a L<KiokuDB::Entry> object.

=back

=head1 AUTHOR

Yuval Kogman <nothingmuch@woobling.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut