Allocation of empty routines from routines with at least minimal code

Is it possible in such a way as not to include the cancellation of the subprogram through B::Deparseor back to its original form? The task is to know if a particular NOT routine reference refers to a predefined object without an actual body (for example package Foo;sub x :ATTR(...); ... sub x { ... }) when an attribute is applied to it (via Attribute::Handlers). At first I thought that the parameter $codewould be undefined in this case, but as it turned out, it is not. Although you can use dewaxing for this task, since such routines return simple ';'as decompiled code through B::Deparse, using it for large functions, it has its own considerations, as well as dependence on this output in all versions of Perl, modules are used, etc. Not really.

+4
source share
1 answer

I think I found a solution without deparsing or size tests. Using module B, I can query

my $cv=B::svref_2object($code);
undef $code if ref $cv->START eq 'B::NULL';

where if ref $cv->START eq 'B::NULL'in my admittedly limited testing is true only and only if sub was only predetermined. It even filters out the subsystems without any type statements sub x{}, exactly as I wish, unlike the previous solution. My only problem with this is the possible differences in different versions of Perl, but I have not been able to find such information yet; In any case, I stick to my current version.

, "Perl Hacks: , " Chromatic, Damian Conway Curtis Poe (). , . , , , CPAN. , CPAN B::TerseSize, , B , . B . , , START - , , CV.

+4

Source: https://habr.com/ru/post/1660573/


All Articles