/usr/share/perl5/KiokuDB/TypeMap/Entry/Closure.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 216 217 218 | package KiokuDB::TypeMap::Entry::Closure;
BEGIN {
$KiokuDB::TypeMap::Entry::Closure::AUTHORITY = 'cpan:NUFFIN';
}
$KiokuDB::TypeMap::Entry::Closure::VERSION = '0.57';
use Moose;
use Carp qw(croak);
use Scalar::Util qw(refaddr);
use PadWalker 1.9;
use Class::Load ();
no warnings 'recursion';
use namespace::clean -except => 'meta';
with qw(KiokuDB::TypeMap::Entry::Std);
sub compile_collapse_body {
my $self = shift;
require B;
require B::Deparse;
return sub {
my ( $collapser, %args ) = @_;
my $sub = $args{object};
my ( $pkg, $name ) = Class::MOP::get_code_info($sub);
my %data;
# FIXME make this customizable on a per sub and per typemap level
if ( $name eq '__ANON__' ) {
my $pad = PadWalker::closed_over($sub);
if ( keys %$pad ) {
my $collapsed_pad = $collapser->visit($pad);
$data{pad} = $collapsed_pad;
my $buffer = $collapser->_buffer;
my $pad_entry_data = blessed $collapsed_pad ? $buffer->id_to_entry( $collapsed_pad->id )->data : $collapsed_pad;
$buffer->first_class->insert(map { $_->id } values %$pad_entry_data ); # maybe only if entry($_->id)->object's refcount is > 1 (only shared closure vars) ?
}
# FIXME find all GVs in the optree and insert refs to them?
# i suppose they should be handled like named...
$data{body} = $self->_deparse($sub);
} else {
( my $pkg_file = "${pkg}.pm" ) =~ s{::}{/}g;
my $file;
if ( my $meta = Class::MOP::get_metaclass_by_name($pkg) ) {
if ( my $method = $meta->get_method($name) ) {
if ( refaddr($method->body) == refaddr($sub)
and
$method->isa("Class::MOP::Method::Generated")
and
$method->can("definition_context")
) {
$file = $method->definition_context->{file};
}
}
}
unless ( defined $file ) {
my $cv = B::svref_2object($sub);
$file = $cv->FILE unless $cv->XSUB; # Can't really tell who called newXS or even bootstrap, so we assume the package .pm did
}
my $inc_key;
if ( defined $file ) {
my %rev_inc = reverse %INC;
$inc_key = $rev_inc{$file};
$inc_key = $file unless defined $inc_key;
}
if ( defined($inc_key) and $pkg_file ne $inc_key ) {
$data{file} = $inc_key;
}
@data{qw(package name)} = ( $pkg, $name );
}
return $collapser->make_entry(
%args,
object => $sub,
data => \%data,
);
};
}
sub _deparse {
my ( $self, $cv ) = @_;
B::Deparse->new->coderef2text($cv);
}
sub compile_expand {
my $self = shift;
return sub {
my ( $linker, $entry ) = @_;
my $data = $entry->data;
if ( exists $data->{body} ) {
my ( $body, $pad ) = @{ $data }{qw(body pad)};
my $inflated_pad;
$linker->inflate_data( $pad, \$inflated_pad );
my $sub = $self->_eval_body( $linker, $body, $inflated_pad );
$linker->register_object( $entry => $sub );
return $sub;
} else {
my $fq = join("::", @{ $data }{qw(package name)});
my $glob = do { no strict 'refs'; *$fq };
unless ( defined(*{$glob}{CODE}) ) {
if ( defined(my $file = $data->{file}) ) {
require $file unless exists $INC{$file};
} else {
Class::Load::load_class($data->{package});
}
unless ( defined(*{$glob}{CODE}) ) {
croak "The subroutine &$data->{name} is no longer defined, but is referred to in the database";
}
}
my $sub = *{$glob}{CODE};
$linker->register_object( $entry => $sub );
return $sub;
}
};
}
sub compile_refresh {
my $self = shift;
return sub {
croak "refreshing of closures is not yet supported";
};
}
sub _eval_body {
my ( $self, $linker, $body, $pad ) = @_;
my ( $sub, $e ) = do {
local $@;
if ( my @vars = keys %$pad ) {
my $vars = join ", ", @vars;
# FIXME Parse::Perl
my $sub = eval "
my ( $vars );
sub $body;
";
my $e = $@;
$linker->queue_finalizer(sub {
PadWalker::set_closed_over($sub, $pad);
}) if $sub;
( $sub, $e );
} else {
eval "sub $body", $@;
}
};
die $e unless $sub;
return $sub;
}
__PACKAGE__->meta->make_immutable;
__PACKAGE__
__END__
=pod
=encoding UTF-8
=head1 NAME
KiokuDB::TypeMap::Entry::Closure
=head1 VERSION
version 0.57
=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
|